0
votes

I'm basically using the C function, fscanf() to read in data from a file. using fopen and checking it I know the file is being opened successfully by checking the return value.

The file is formatted with Char, Int, Int. The issue I have is I can only read in one line at a time and the loop exits. Would appreciate if anyone could see where I am going wrong

char c;     
char nl;    
int t1, t2; 
int dataTest; 
do
{
    dataTest = fscanf(fp, "%c %d %d", &c, &t1, &t2);
    fscanf(fp, "%c", &nl);
    printf("%c %d %d \n", c, t1, t2);
    if (dataTest = -1)
    {
        break;
    }
}while(1);
1
strive for a minimal example. in this case most of the code(& description!) is not necessary to reproduce the problem. - Karoly Horvath

1 Answers

2
votes

You want

if(datatest==-1)

rather than

if(datatest = -1)

One tests equality, while the other is an assignment expression. Any "assignment expression" in C will return the value to which the variable is assigned. So for example, datatest= -1 will return -1.