I've been working on this for 2 hours and I am stuck... I found the answer online, but that isn't going to help me learn the concept that I'm obviously missing.
Prompt: Write a program to copy its input to its output, replacing each tab by \t
, each backspace by \b
, and each backslash by \\
. This makes tabs and backspaces visible in an unambiguous way.
Here's what I came up with, it doesn't replace a tab
or \
with the indicated putchar
, it just adds it in front of it.(I didn't do backspace because I can't really input a backspace...):
This is how I read the code. What am I missing?:
"There is some integer c
. c
is equal to the input. When the input is not equal to end of file proceed. If input is tab then the output \t
. If input is \
then output \\
. Output the input to console."
int c;
while((c=getchar())!=EOF)
{
if(c=='\t')
{
putchar('\\');
putchar('t');
}
if(c=='\\')
{
putchar('\\');
putchar('\\');
}
putchar(c);
}