How do I loop through a string of chars?
I have a private data member say (char *string1).
I wrote the following code.
for (char* temp=string1; *temp!='/0'; ++temp)
When I try to run this code I get an access violation error!
due to this *temp!='/0' part
so how am I suppose to go through a cstring??
Thanks
Re: How do I loop through a string of chars?
Quote:
Originally posted by silverfoxtp
I have a private data member say (char *string1).
I wrote the following code.
for (char* temp=string1; *temp!='/0'; ++temp)
When I try to run this code I get an access violation error!
due to this *temp!='/0' part
so how am I suppose to go through a cstring??
Thanks
That code is correct. I would guess that string1 points to invalid memory. Post some more code.
>> fizisyen: temp != '\0'
Nope. That just compares the pointer to 0 (NULL), which it shouldn't be if the code is working properly.