while loop is not working

int main()
char a,roll[51];
int i=0;



return 0;

you can not write <’\0’ cozz it is a null chracter and we can not compare it.
use dis one

It is not like you cannot compare ‘\0’ as @shilpa_12345 has said. Characters are in fact stored as integers only according to their ASCII values. Your code is perfectly fine and your while loop also works fine. Only thing is your logic might be wrong which is why you are not getting the results you are expecting. ‘\0’ has an ASCII value of decimal 0. So if you input any numbers or characters, the expression while(roll[i]<=’\0’) will always evaluate to false as any numbers or alphabets ASCII values are greater than decimal 0. So basically, what ever you type in numbers and alphabets, the while loop wont get executed at all.

Try to run your code with special characters like plus '+', '(', ')' etc, it will work perfectly. So, instead, if you want to iterate through every characters read via scanf(), you would want to check if ‘\0’ is reached as follows:

while(roll[i] != '\0')
1 Like