reading multiple variable types from single line in file C

后端 未结 5 1203
无人及你
无人及你 2021-01-27 14:09

Alright I\'ve been at this all day and can\'t for the life of me get this down, maybe you chaps can help. I have a file that reads as follows

1301,1055150

5条回答
  •  无人及你
    2021-01-27 14:32

    With the fscanf format string "%d,%d,\"%[^\"]\",\"%[^\"]\",%[^,],%d,=\"%[^\"]\"" we can read a whole line's data. Besides, you have to define

    char lastname[MAX_NAME+1];
    char firstname[MAX_NAME+1];
    char subjectname[MAX_SUBSEC+1];
    int catalog;
    char section[MAX_SUBSEC+1];
    

    — the +1 to account for the terminating '\0' character.

提交回复
热议问题