char problem

K

Kay

I have obtained whole sentence by using this. If the sentence like this

Sentence 1: Harry Protter; M; 15
Sentence 2: Peter Parker; M; 23

char wholeLine[45];
//obtain the whole string
fgets(wholeLine, 45, ptr);

how can I break up this sentence without storing the semi-colon and save
it into three different character array?

some one told me that it can be done by this

char rest_name[40];
rest_name = strtok( wholeLine, ';');

But It can't do it, anyone can guide me ? Thx
 
R

Ravi Uday

Kay said:
I have obtained whole sentence by using this. If the sentence like this

Sentence 1: Harry Protter; M; 15
Sentence 2: Peter Parker; M; 23

char wholeLine[45];
//obtain the whole string
fgets(wholeLine, 45, ptr);

how can I break up this sentence without storing the semi-colon and save
it into three different character array?

some one told me that it can be done by this

char rest_name[40];
rest_name = strtok( wholeLine, ';');

But It can't do it, anyone can guide me ? Thx

Dude..
Your query was addressed just a couple of days before in the same group.

Subj: fscanf and linked list problem

Dont repost !!

- Ravi
 
M

Malcolm

Kay said:
I have obtained whole sentence by using this. If the sentence like this

Sentence 1: Harry Protter; M; 15
Sentence 2: Peter Parker; M; 23

char wholeLine[45];
//obtain the whole string
fgets(wholeLine, 45, ptr);

how can I break up this sentence without storing the semi-colon and save
it into three different character array?

some one told me that it can be done by this

char rest_name[40];
rest_name = strtok( wholeLine, ';');

But It can't do it, anyone can guide me ? Thx
Firstly, a buffer of 45 characters is rather mean. Unless there is a limit
imposed by your format, why not use 1024?

Secondly, strtok() returns a pointer to the portion of the string after the
separator, and replaces the separator with a NUL. It does not return an
array of characters.
It is quite a tricky function to use, so read your documentation carefully.
 

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,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top