I come across this KR exercise 1-10:
Write a program to copy its input to its output, replace each tab by t, each backspace by b, and each backslash by \ .
Here's a very simple solution:
#include <stdio.h>
int main()
{
int c;
const char TAB = 't';
const char BACKSPACE = 'b';
const char BACKSLASH = '\';
while( EOF != ( c = getchar() ) )
{
if( TAB == c )
{
printf( "\t" );
}
else if( BACKSPACE == c )
{
printf( "\b" );
}
else if( BACKSLASH == c )
{
printf( "\\" );
}
else
{
putchar( c );
}
}
return 0;
}
I found the it works ok to visualize Tab and (Backslash) but not Backspace. Looks like Backspaces are not remembered by the console? I'm on Ubuntu 14.04.
This seems a similar issue, but not quite sure it's the same.
Aucun commentaire:
Enregistrer un commentaire