0
#define TERMMAX 100
typedef struct{
    int coef;
    int expon;
} poly;
poly term[TERMMAX];
int avail = 0;

#define TERMMAX 100
enter code here
int main()
{
    int i;
    FILE *fp = fopen("a.txt", "r");

    while(fscanf(fp, "%d\t%d", &term[avail].coef, &term[avail].expon) != EOF)
        avail++;

the fscanf part above works just fine but the following fscanf doesn't.

    while(fscanf(fp, "%d\t%d", &term[avail].coef, &term[avail++].expon) != EOF)
        ;

Nothing is stored in term[].expon. Why?

장동욱
  • 17
  • 6
  • 1
    The `scanf` family does not return `EOF`, they return the number of items successfully scanned. – paxdiablo Mar 29 '17 at 01:02
  • This is undefined behaviour due to incorrect assumptions you have made about sequence points. Will mark as a duplicate with relevant answer. – paddy Mar 29 '17 at 01:15
  • 2
    Possible duplicate of [Parameter evaluation order before a function calling in C](http://stackoverflow.com/questions/376278/parameter-evaluation-order-before-a-function-calling-in-c) – paddy Mar 29 '17 at 01:15

1 Answers1

2

IIRC, the order of evaluation of function parameters is unspecified by the Standard. Any side effects of function parameters are indeterminately sequenced.

D.Shawley
  • 58,213
  • 10
  • 98
  • 113