Home > Archive > C > August 2004 > char problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| 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
| |
| Ravi Uday 2004-08-30, 8:55 am |
|
"Kay" <ericjo92003@yahoo.com.hk> wrote in message
news:4132DB31.30200@yahoo.com.hk...
> 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
| |
| Malcolm 2004-08-30, 8:55 pm |
|
"Kay" <ericjo92003@yahoo.com.hk> wrote
> 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.
|
|
|
|
|