#include <stdio.h>
int main() {
int c;
while ((c = getchar()) != EOF) {
if (c == '\t')
printf("\\t");
else if (c == '\b')
printf("\\b");
else if (c == '\\')
printf("\\\\");
else
putchar(c);
}
return 0;
}
In this case for an input of
hi how are you\doing
I get an output
hi\thow\tare\tyou\\doing
#include <stdio.h>
int main() {
int c;
while ((c = getchar()) != EOF) {
if (c == '\t') {
c = '\b';
printf("\\t");
}
if (c == '\b') {
c = '\b';
printf("\\b");
}
if (c == '\\') {
c = '\b';
printf("\\\\");
}
putchar(c);
}
return 0;
}
When I run this program with an input
hi how are you\doing
(The large spaces being tabs)
I get this output
hi\t\how\t\are\t\you\doing
Code:
#include <stdio.h>
int main() {
int c;
c = '\b';
putchar(c);
return 0;
}
On running this, I get nothing. No output. Back to the shell prompt.
To be more precise, in the first program I get the output I want, but in the second program I get the backslashes after every \t
but not after the \
I would expect \\\
to be the output looking at how \t
became \t\
, is '\b' causing it? if it is, how does it work? but if so why doesn't the same happen in the third program?
Ran this on rasbian default gcc compiler and mingw msys-gcc package for windows.