txt 파일에서 모든 줄을 인쇄 할 수 있어야하는이 프로그램을 작성했습니다. 단 하나만 인쇄하고 1 시간 동안 보았지만 실수는 없습니다. 도움이 appriciated 것입니다! :)txt 파일에서 모든 줄 인쇄 프로그램이 없습니다
1 16.07.2011 kl. 17.00 OB - FCN 2 - 0 6.965
1 17.07.2011 kl. 14.00 FCM - SIF 1 - 2 5.370
1 17.07.2011 kl. 16.00 ACH - HBK 3 - 0 2.227
1 17.07.2011 kl. 16.00 SDR - FCK 0 - 2 4.992
처음 4 줄.
#include <stdio.h>
#include <stdlib.h>
#define MAX_LINE_LGT 200
#define NAME_MAX 200
#define TEAM_MAX 200
struct team{
char name[NAME_MAX];
int five_or_more_goals;
};
typedef struct team team;
void read_data_1(const char *file_name, team teams[]){
FILE *ifp;
char team1[NAME_MAX];
char team2[NAME_MAX];
int goal1, goal2;
int dag, month, year;
double clock;
int attendance;
int round;
team local_match;
ifp = fopen(file_name, "r");
while (fscanf(ifp, "%d %d.%d.%d kl. %lf %4s - %4s %d - %d %d\n", &round, &dag, &month, &year, &clock, team1, team2, &goal1, &goal2, &attendance) == 10){
printf("runde %d den %d %d %d klokken %.2lf, mellem %s og %s endte %d - %d %d så kampen\n", round, dag, month, year, clock, team1, team2, goal1, goal2, attendance);
}
fclose(ifp);
}
int main(void) {
team all_matches_teams[TEAM_MAX];
read_data_1("superliga-2011-2012", all_matches_teams);
return 0;
}
파일을 보지 않고 진행 상황을 알리는 것은 불가능합니다. 사실, 전체 파일조차도 처음 3 ~ 4 줄이면 충분합니다. – dasblinkenlight
포맷 문자열의 끝에서'\ n'을 제거합니다. 어쨌든 건너 뛸 것이고, 마지막 줄에는 형식 문자열이 없을 수도 있습니다. – dasblinkenlight
fscanf가 두 번째로 반환하는 것은 무엇입니까? –