reading a csv file into struct array

前端 未结 3 1466
时光说笑
时光说笑 2021-01-15 13:29

I\'m beginning to code in C. My code is as follows:

#include 
#include 
#include 

#define MAX_STR_LEN 256
#de         


        
3条回答
  •  死守一世寂寞
    2021-01-15 13:39

    The reason is that in something like

    books[i].name = tmp;
    

    You're not actually copying a string from tmp into books[i].name: you just make both point to the same location - somewhere into the buf buffer.

    Try using strdup instead, as in:

    books[i].name = strdup(tmp);
    

提交回复
热议问题