The following code uses getchar () to receive an input line.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *rawString = (char *)malloc(200*sizeof(char));
char *rawStringInitial = rawString;
char c;
c=getchar();
while(c!='\n')
{
*rawString=c;
rawString++;
c=getchar();
}
*rawString='\0';
printf("\n[%s]\n",rawStringInitial);
return(0);
}
When typing, if I press backspace, should I also not get getchar () it and store it in the place specified in rawString? However, the output simply displays the final line without any special characters. Can someone explain why?
user191776
source
share