"i = 5" is assignment, not comparison. "i == 5" is comparison.
The middle statement in a for loop is the condition to keep looping. As long as that condition is true, the loop keeps running. Using "i < 5" is what you probably want to use.
If you just want to print the string, you don't need a loop. Just do:
But if you want to do something else with the characters of the string, there are two or three different ways you can approach this:
Code:
#include <cstring>
int len = strlen(h);
for (int i = 0; i < len; i++) {
// do stuff with h[i]
}
Code:
for (int i = 0; h[i] != '\0'; i++) {
// do stuff with h[i]
}
Code:
// If you can change the pointer, not applicable in your case
while (*h != '\0') {
// do stuff with *h
++h;
}
Lastly, I know you're simply learning right now, but remember to prefer C++ strings to the old C-strings, they're far more easy to use.