string problem

Thread Starter

braddy

Joined Dec 29, 2004
83
Hi , I need suggestion on how to do the following task in standard C:

I have a set of 5 cards like:

king of clubs
six of clubs
four of diamonds
six of hearts
four of hearts

I need read the 5 lines (strings) from a file, and count how many,words"six" and words "heart" I have in this set.


If I read the line with fgets, how can I discriminate the words"six" and "heart" from the whole line, for example?

I suspect pointers and the function strcmp but I dont know how to use them..
Please Can I have some indications?
Thank you for your help.
B
 

Papabravo

Joined Feb 24, 2006
13,972
Originally posted by braddy@Mar 10 2006, 05:57 PM
Hi , I need suggestion on how to do the following task in standard C:

I have a set of 5 cards like:

king of clubs
six of clubs
four of diamonds
six of hearts
four of hearts

I need read the 5 lines (strings) from a file, and count how many,words"six" and words "heart" I have in this set.


If I read the line with fgets, how can I discriminate the words"six" and "heart" from the whole line, for example?

I suspect pointers and the function strcmp but I dont know how to use them..
Please Can I have some indications?
Thank you for your help.
B
[post=14850]Quoted post[/post]​
The function you want is "strtok" it converts a string to individual tokens. Each token in the string can be treated as if it was a null terminated string in its own right. Exert some effort on learning how to use this function, it will be well rewarded.
 
Top