Parsing a Comma Separated String in C

Joined
Sep 6, 2006
Messages
1
Reaction score
0
Dear friends

How do i write a small C function which accepts a comma separated string . the string could be either like ("Hi", "How", "You" ) or hi, how, are, you . nad parse it and output should be displayed like
hi
how
are
you
How to split the string on the first value and stored it in a separete string variable and display it
Thanks
Ronan
 
Joined
Nov 9, 2006
Messages
4
Reaction score
0
char *str="hi,how,are,you";
char *val; int i,j=0;

while((str+j)!='\0'){

i=0;

while(*(str+j)!=',')
{
*(val+i)=*(str+j);
j++;
i++;
}
printf("%s",val);
j++;
}
}

hope it would be helpful
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top