S
Sathyaish
In trying to replace character literals for their char constant, I am
having difficulty printing the char constant for backslash. It instead
prints the char literal. How do I resovle this?
#include <stdio.h>
/*A program that reads keyboard input and reproduces it on the monitor
with some modifications.
It displays all newline character occurences as \n, tabs as \t and
backslashes as \\.
Basically, it replaces some of the characters with their character
constants.
*/
void main()
{
int c;
while ((c=getchar()) != EOF)
{
if ((char)c=='\n')
{
printf("\\n");
putchar(c);
}
else if ((char)c=='\t')
{
printf("\\t");
}
else if ((char)c=='\\')
{
printf("\\");
}
else
{
putchar(c);
}
} //end of while loop
} // end of main
I want that when I type a backslash, the output must be replaced with
\\, the character constant for backslash.
having difficulty printing the char constant for backslash. It instead
prints the char literal. How do I resovle this?
#include <stdio.h>
/*A program that reads keyboard input and reproduces it on the monitor
with some modifications.
It displays all newline character occurences as \n, tabs as \t and
backslashes as \\.
Basically, it replaces some of the characters with their character
constants.
*/
void main()
{
int c;
while ((c=getchar()) != EOF)
{
if ((char)c=='\n')
{
printf("\\n");
putchar(c);
}
else if ((char)c=='\t')
{
printf("\\t");
}
else if ((char)c=='\\')
{
printf("\\");
}
else
{
putchar(c);
}
} //end of while loop
} // end of main
I want that when I type a backslash, the output must be replaced with
\\, the character constant for backslash.