Solved

Character iterator

Posted on 2006-10-20
3
244 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:jamie_lynn
3 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 17778149
Hi jamie_lynn,

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

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

Cheers!
sunnycoder
0
 

Author Comment

by:jamie_lynn
ID: 17778173
Thanks Sunnycoder!
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 17778215
Hi jamie_lynn,

Just a quick extra.

This works too, you choose:

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


Paul
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question