Okay, for example I have this code,
And when I run the code,Code:char str[20]; char chr; int num; /* Case 1 */ printf("\nNum: "); scanf("%d", &num); printf("\nStr: "); scanf("%s", str); printf("\nLetter: %d", str[0]); /* Case 2 */ printf("\nNum: "); scanf("%d", &num); printf("\nChr: "); scanf("%c", &chr); printf("\nLetter: %d", chr);
On case 1: the str[0] has value of the first character of whatever you inputted.
On case 2: the chr has value of LineFeed (ASCII 10).
Now for my question,
Why on case 1 the str does not take the LineFeed character ?
Whereas on case 2, the chr takes the LineFeed character ?
Aren't both string and character supposed to take everything inputted into them?
I hope you get my meaning..
Thanks.



LinkBack URL
About LinkBacks


