Printing chars in char array individually with spaces

I'm trying to write a function that prints out each character of a char array one by one. Here's what I currently have:

1
2
3
4
5
6
7
8
void tprint(char sSay[], int time)
{
	for(int c=0; c<=sizeof(sSay); c++){
		cout << sSay[c] << flush;
		_sleep(time);
	}
	//cout << "\n" << sSay << endl;
}


This seems like it should work, but whenever I try it, the characters get printed out individually up to the end of the first word (I'm using the string "Hello, world." as a test, and it just prints "Hello"., and then it stops. Why does this happen? How can I fix it? Thanks.

EDIT: I tried sizeof(sSay)+10 in the 3rd line and it prints out everything just fine. I think something is messed up with the apparent size of the array. Any suggestions?
Last edited on
indeed. sizeof(sSay) = 4, because sSay is a char* (thats how passing arrays works in c++). you need to use c < strlen(sSay) or sSay[c] != 0 (if sSay is a cstring. otherwise you'll have to pass the length of the string into tprint)
c<strlen(sSay) works like a charm. Thank you very much! :)
Topic archived. No new replies allowed.