C, reading from file into structure

前端 未结 1 1593
抹茶落季
抹茶落季 2020-11-29 09:47

I\'ve been struggling with this for days and I can\'t figure out why it doesn\'t work.

I\'m trying to read numbers from file with numbers written like this:

相关标签:
1条回答
  • 2020-11-29 10:21
    fscanf(reads,"%d %d %d %d %lf", n->id, n->sign, n->year, n->month, n->amount);
    

    The scanf family of functions expect addresses. Change the fscanf line to:

    fscanf(reads,"%d %d %d %d %lf", &n->id, &n->sign, &n->year,
        &n->month, &n->amount);
    

    Side note, this is a seriously misleading line:

    else { while(!feof(reads)) {
    
    0 讨论(0)
提交回复
热议问题