Break the string into different parts

Y

yezi

Hi:

I want to break a string like "30 23 date" into 3 parts in C:

int 30;
int 23;
char string date;

Do not know how to get it.

Thanks in advance .
 
J

John Bode

yezi said:
Hi:

I want to break a string like "30 23 date" into 3 parts in C:

int 30;
int 23;
char string date;

Do not know how to get it.

Thanks in advance .

Use one of strtok() or strchr() to break the string apart into
substrings, then use strtol() to convert the strings "30" and "23" into
the integral values 30 and 23.

This smells like a homework question, so I'm not going to post a
complete solution (yet). Read up on strtok(), strchr(), and strtol(),
give it a shot, and if you run into problems feel free to ask more
questions.
 
M

Mark B

John Bode said:
Use one of strtok() or strchr() to break the string apart into
substrings, then use strtol() to convert the strings "30" and "23" into
the integral values 30 and 23.

strtol() alone can handle this task (hint: 2nd argument ;)
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top