example code is (comments are what I imagine it's doing for the first loop):
#include <stdio.h>
#define BACKSPACE 8
main()
{
int c;
while((c = getchar()) != EOF) //output: GODDAMN NOTHING cursor on: 'h'
{
//if the input is "house" before entering EOF
putchar(c); //output: 'h' cursor on: 'o'
getchar(); //output: 'h' cursor on: 'u'
printf("%c", BACKSPACE); //output: 'h' cursor on: 'o'
getchar(); //output: 'h' cursor on: 'u'
printf("%c", BACKSPACE); //output: 'h' cursor on: 'o'
getchar(); //output: 'h' cursor on: 'u'
printf("%c", BACKSPACE); //output: 'h' cursor on: 'o'
}
} //ACTUAL END OUTPUT: "h"
I know regular backspacing in most programs looks like: printf("%c %c", 8 ,8); ..meaning backspace pretty much just moves the cursor back without deleting anything, just like how getchar() just moves the cursor forward.
I'm trying to understand why the sample code above's output isn't exactly the same as:
#include <stdio.h>
main()
{
int c;
while((c = getchar()) != EOF) //output: WE HAVE NOTHING cursor on: 'h'
{
//if the input is "house" before entering EOF
putchar(c); //output: 'h' cursor on: 'o'
}
} //ACTUAL END OUTPUT: "house"
EDIT: follow up question! How do I "reverse" a getchar() call?
#include <stdio.h>
main()
{
int c;
char a;
while((c = getchar()) != EOF)
{
a = c;
putchar(c);
a = getchar();
??????????
}
}
what do I have to put on "??????????", so that when I call getchar again to assign to c, it gets the char after the preceding assignment to c, and not the char after a.