Created
July 6, 2015 15:09
-
-
Save keita03301995/f13bfe7aa9b60620becf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define NUM 100 | |
void read(FILE *fp); | |
int main( int argc, char *argv[NUM] ) | |
{ | |
FILE *fp; | |
int i; | |
char filename[NUM]; | |
sprintf(filename,"C:\\Users\\啓汰\\Downloads\\BC PAD\\課題12DataFile\\%s",argv[1]); | |
fp = fopen(filename,"r"); | |
if ( fp == NULL ) | |
{ | |
printf("エラー\n"); | |
return 1; | |
} | |
if ( argc < 2 ) | |
{ | |
printf("引数不足"); | |
return 1; | |
} | |
read(fp); | |
fclose(fp); | |
return 0; | |
} | |
void read(FILE *fp) | |
{ | |
int field,ichi,ni,san,i,j,date,all; | |
char gakuseki[NUM]; | |
double avg; | |
printf("フィールド入力-->"); | |
scanf("%d",&field); | |
i = 0; | |
all = 0; | |
while ( fscanf(fp,"%s ",gakuseki) != NULL ) | |
{ | |
for ( j = 1; j <= 3; j++ ) | |
{ | |
fscanf(fp,"%d ",&date); | |
if ( j == field && i < 5 ) | |
{ | |
printf("%d, ",date); | |
} | |
else if ( j == field && i == 5 ) | |
{ | |
printf("%d ",date); | |
} | |
all += date; | |
} | |
i++; | |
} | |
avg = (double)all/6; | |
printf("\n平均:%.1f",avg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
6ってどっからでてきた!?今回確かにファイルの中身は6個だけど、これファイルの中身が変わると対応できなくなるよー。ちゃんと数は計算すること