Simple C program exits prematurely -
I'm trying to create a program (my first) which asks users for four inputs, and long It's been running from time to time that the four ASCII values are not 0. However, my code never reaches the loop part and always exits after the initial printf statement. I'm sure there was no problem in the loop by adding a printf statement before the loop and it still did not execute.
#include & lt; Stdio.h & gt; Int main (zero) {four c; Printf ("Welcome to ASCII Land:"); Scanf ("% c", & amp; c); While ((int) 'c'! = 0) {printf ("type in other type"); Scanf ("% c", & amp; c); } Printf ("You've done"); Return 0; }
By default it converts 'C' to a number and compares to 0. C 'is actually 99, so you're saying while ((int) 'c'! = 0) {
should be while (c! = '0') {
while (99! = 0)
. Just by removing quotation marks from 'c', how do you "enter? ASCII 0 (NUL)"?
Comments
Post a Comment