Solved

Character iterator

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand recursion 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.

914 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

16 Experts available now in Live!

Get 1:1 Help Now