One of the training exercises in my C programming book goes like following: (translated from swedish)
If you use a writing/typing terminal you kan sometimes, just like a normal typewriter, underline a word by stepping back on the line and writing _ under the word. Write a program that writes the string in the variable
s
underlined.
my attempt looks like this:
#include <stdio.h>
int main(void) {
char *s;
printf("input: ");
scanf("%ms", &s);
for (int i=0; s[i] != '\0'; i++) {
printf("%c\b_", s[i]);
}
printf("\n");
return 0;
}
This does not work i expect terminal output to be:
$> gcc -Wall -std=c99 file.c
$> ./file.c
input: test
test //underlined
$>
but instead i get:
$> gcc -Wall -std=c99 file.c
$> ./file.c
input: test
____
$>
does anyone know how to do that or is the book wrong?