My code is behaving weirdly. In loop 1 it is working perfectly but in loop 2 it is automatically printing ASCII value 10. please help!.
#include<stdio.h> int main(){ char c; int loop =1; do{ printf(" Loop = %d Write character of which you want to find acii values: ", loop); scanf("%c", &c); printf(" ASCII value of %c is %d.", c, c); loop++; }while(c != 'Z'); printf(" ******END*****"); return 0; }
10 is ASCII for newline. You are reading whitespace, which you can avoid by using
scanf(" %c", &c);
Note the additional blank before the character specifier. It instructs scanf to ignore white space.
2.1m questions
2.1m answers
60 comments
57.0k users