You are not logged in. Please login at www.codechef.com to post your questions!

×

# include<string.h>

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

scanf("%s",&roll);
while(roll[i]<='\0'){


printf("%c\n",roll[i]); i++; }

return 0; }

asked 30 Jun '17, 19:42

1
accept rate: 0%

 1 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')  answered 30 Jun '17, 20:48 723●1●1●8 accept rate: 12%
 0 you can not write <'\0' cozz it is a null chracter and we can not compare it. use dis one while(roll[i]!='\0') answered 30 Jun '17, 20:05 1●2 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×43
×4

question asked: 30 Jun '17, 19:42

question was seen: 207 times

last updated: 30 Jun '17, 20:48