Solved

Character iterator

Posted on 2006-10-20
3
240 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now