//讀取文件數據 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> struct jiang{ char one[50]; char two[50]; }str[13]; void main(){ //定義數據 int arr[5] = { 0 }; //定義文件路徑 char path[40] = "E:\\Look\\b.txt"; //定義文件指針 FILE *pf=NULL; //打開讀寫文件 pf = fopen(path, "r"); //判斷是否打開文件 if (pf==NULL) { printf("文件打開失敗!"); return; } int index = 0; //讀文件 while (!feof(pf)){ //\t就是文本中的空格,不管有多少個空格 都是一個\t fscanf(pf, "%s\t%s\n", str[index].one, str[index].two); index++; } //關閉文件指針 if (pf!=NULL) { fclose(pf); } for (int i = 0; i < 13; i++) { printf("%s,%s\n", str[i].one, str[i].two); } system("pause"); }

