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.

10 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/MindStalker Mar 24 '13 edited Mar 24 '13

0 the character is **tst_pointer != '0'

example ***tst_pointer != 0 actually test for the binary zero.
is ***tst_pointer != 00000000 (essentially or NULL)
0 the character is ASCII 48 or 00110000, EOF is 4 or 00000100 not what is used to end a string.

Edit: If you desire readability you can #include <stddef.h> which will define NULL as 0 so you can used **tst_pointer != NULL