标记化的格式" ..."字符串

时间:2014-10-06 02:36:45

标签: c

假设我有包含数据的文件

Data1 "X1 Y1 Z1"
Data2 "X2 Y2 Z2"
Data3 "X3 Y3 Z3"

通常,我如何扫描文件并将我的程序计为“X1 Y1 Z1”作为单个标记?

1 个答案:

答案 0 :(得分:2)

#include <stdio.h>

int main(){
    FILE *fp = fopen("data.txt", "r");
    char data_name[16];
    char data_string[32];

    while(2==fscanf(fp, "%15s \"%31[^\"]\"", data_name, data_string)){
        printf("%s, %s\n", data_name, data_string);
    }
    fclose(fp);
    return 0;
}