We help IT Professionals succeed at work.

Character iterator

jamie_lynn
jamie_lynn used Ask the Experts™
on
Hi,
I'm trying to iterate each character from a string.
What is the most efficient and best way?

i.e.
char *s = "abcdefg";
I want to loop that pops the first character.
So get 'a' then 'b', then  'c', 'd', etc.

Thanks
Jamie
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
Commented:
Hi jamie_lynn,

char * s = "abcdefg";
char * temp = s;

while ( *s != '\0' )
{
         printf ("current char %c\n",*s);
         s++;
}

Cheers!
sunnycoder

Author

Commented:
Thanks Sunnycoder!
Hi jamie_lynn,

Just a quick extra.

This works too, you choose:

for ( ;*s; s++ ) {
}


Paul