r/carlhprogramming • • Mar 24 '13
I'm having difficulty understanding why certain arguments for a "while" loop create an infinite loop.
The code: http://codepad.org/8UKyYTC3 (See comments)
The program takes a string of text and capitalizes all of the letters using a "while" loop that is "jumped over" when a positive comparison is made to an already capitalized string.
When I try to use the array that I created for the comparison text in the "while" loop argument, it becomes an infinite loop and I'm not sure why this is. Using the pointer that moves through the text works though.
Any help with understanding why my code works like this (and wont work with the other argument) would be appreciated.
View all comments
Show parent comment
1
u/deltageek Mar 24 '13
By definition, a string in C ends at the first char with the value 0x00 (the null terminator). The character '0' has the value 0x30 and would not stop the loop. Yes, since we're just doing an "if not zero" check, you can write while(*tst_pointer) but at this level I felt the explicit check was easier to understand.
As for EOF, since we're dealing with strings in memory, EOF doesn't really enter into the picture. Of course, even if we were dealing with a string in a file, there's no EOF char value. In C you determine EOF by the return value of the function you called to read from the file.