string problem

Discussion in 'Programmer's Corner' started by braddy, Mar 10, 2006.

  1. braddy

    Thread Starter Well-Known Member

    Dec 29, 2004
    83
    0
    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
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    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.
     
Loading...