I am having trouble with stopping a while loop when a char array reaches '\\0'. I understand that this is the always the last element of any char array and so I do not understand why the code below never ends the loop. Any help would is appreciated.
char randomString[] = "testSTRING";
int counter = 0;
while (randomString[counter] != '\0')
cout << "test";
Try this:
char randomString[] = "testSTRING";
int counter = 0;
while (randomString[counter++] != '\0')`
cout << "test";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.