Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Character iterator

Posted on 2006-10-20
3
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
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.

648 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