我們得到了一個任務,讓程序讀取我們的文本文件(姓名,學號,課程,年份,部分等等..但我似乎無法讓它工作,你能告訴我什麼是錯的嗎?無法讀取我寫的文件(C編程學生數據庫)
#include <windows.h>
#include <conio.h>
#include <stdio.h>
struct record
{
char name[50],number[50],course[50],gender;
int year, section;
float midterm,final,average,sum;
};
int main()
{
int a=1,n;
int passed=0,failed=0;
FILE *fp;
fp = fopen("StudentPUP.txt","r");
if(fp==NULL)
{
printf("ERROR!");
getch();
}
struct record student[25];
printf("Please input the number of students: ");
scanf("%d", &n);
for(a=0;a<n;a++)
{
fscanf(fp, "%f", student[a].average);// I CANNOT MAKE THE FSCANF WORK!!//
}
getch();
}
This是寫在我的文本文件裏面。輸入文件的
前幾行:
Student Name: Mark Benedict D. Lutab
Gender: M
Student Number: 2015-04711-MN-0
Course: BSIT
Year: 1
Section: 2
Midterm Grade: 2.00
Final Grade: 1.75
Average Grade: 1.8
Student Name: Andrea Zoelle S. Jacinto
Gender: F
Student Number: 2015-04711-MN-0
<etc.>
如果您不只是在鍵入'c'時標記出現的每種編程語言,都會很感激。 – miradulo
不應該是'fscanf(fp,「%f」,&(student [a] .average));'? –
根據您必須閱讀的內容,您必須處理文件內容,即您存儲哪種格式的詳細信息。 –