Hi,

Basically I'm trying to read a text file into a C program line by line and then act on each line.

The text file I am reading looks like this:
Code:
RUN 5
SET 1 1
RUN 5
SET 2 1
RUN 5
SET 1 0
RUN 3
SET 3 0
RUN 2
SET 2 0
RUN 5
Each line can have one of two formats; either SET 3 1, which is setting node 3 equal to 1. Or Run 5 which means run 5 times.

I am trying to read in a line, store the 3 letter word (set or run) as a string, if it is "Set" then storing the two numbers that follow, if it is "Run" then storing the one number that follows.

The stored info can then be used to do the necessary processes.

Any ideas?

I've already had a play around with fgets, fread and fscanf but to no avail. Here is a piece of code I used earlier in the program to read in data from a slightly different text file and store it in structures:
Code:
 
    typedef struct
        {
         char GateType[4];
         int OutputNode;
         int InputNode1;
         int InputNode2;
        } LogicGate;

...

while(fscanf(fp, "%s %d %d %d", &LogicGates[index].GateType, &LogicGates[index].OutputNode, &LogicGates[index].InputNode1, &LogicGates[index].InputNode2) == 4)
This worked fine and was easy because of the uniformity of that file..
AND 6 1 3
XOR 5 3 4
AND 7 5 2
XOR 8 6 7
where each line had four components.

Is there a way of modifying this to suit? or do I need to do something completely different?

Thanks,