我正在維護計算機專業學生的集合的數據庫進行簡單的註冊系統。每個學生記錄包含從文件中讀取7個變量(每個變量1號線),並分配給結構變量
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
char name[300];
int age;
char course_1[40];
char course_2[40];
char *remarks;
};
struct course
{
char course_title[200];
int cse_num[100];
char instructor[200];
char date[50];
char start_time[50];
char end_time[50];
char location[50];
};
main()
{
int i;
struct course data[11];
FILE *f;
char title[100];
int num[100];
char instructor[100];
char date[100];
char start_time[100];
char end_time[100];
char location[100];
char line[300];
f = fopen("course.dat", "r");
i=0;
while(*fgets(line, 300, f) != '\n')
{
sscanf(line, "%99[^\n]", num);
sscanf(line, "%99[^\n]", title);
sscanf(line, "%99[^\n]", instructor);
sscanf(line, "%99[^\n]", date);
sscanf(line, "%99[^\n]", start_time);
sscanf(line, "%99[^\n]", end_time);
sscanf(line, "%99[^\n]", location);
data[i].cse_num = num // doesn't work
strcpy(data[i].course_title, title);
strcpy(data[i].instructor, instructor);
strcpy(data[i].date, date);
strcpy(data[i].start_time, start_time);
strcpy(data[i].end_time, end_time);
strcpy(data[i].location, location);
i++;
}
fclose(f);
}
我的問題是如何在輸入需要從文件,因爲它是7行,直到一個新行考慮。我盡我所能解釋這一點,謝謝你,如果你可以嘗試幫助我的傢伙!我真的專注於這一點,只是不能說實話。這是文件:
示例輸入:
CSE1001
Research Directions in Computing
Wildes, Richard
W
16:30
17:30
VC 135
我建議重新標記您的問題到c – apomene 2013-03-25 19:05:23
1.你提供看起來並不像C#2可怕的格式(請您在使用橙色問號的代碼發佈以瞭解如何格式化)3.巨大的文本牆。不要發佈整個程序,不要發佈整個文件。發佈相關的代碼和簡要的輸入示例。 4.你還沒有自己嘗試過這個問題,但你或者 – tnw 2013-03-25 19:05:52
你的代碼喜歡c,但你用c#來關閉它。你在說什麼語言? – evgenyl 2013-03-25 19:06:55