|
学生番号と身長(cm)の組を多数入力し、入力したデータをそのまま出力する。ただし、
身長が180以上の場合だけ'tall'という文字を横に付け加える。入力データのストッパは 学生番号=身長=0とする (入力例) (出力例) 1001 168 1001 168 1002 176 1002 176 1004 182 1004 182 tall 0 0 #include <stdio.h>
#include <string.h>
#define N 20
typedef struct {
int b; /*学生番号*/
int t; /*身長*/
char k[10]; /*結果*/
}Student;
int main( ){
FILE *fp;
Student stu[N+1];
int i = 0;
printf("学生番号、身長を半角スペースを空けて入力(終了条件:Ctrl+Z)\n");
while( (scanf("%d %d",&stu[i].b,&stu[i].t)!=EOF) && i<N){
if(stu[i].t >= 180){
strcpy(stu[i].k,"tall");
}
else{
strcpy(stu[i].k," ");
}
i++;
}
fp = fopen("text.txt","w");
if(fp == NULL){
printf("ファイルNG\n");
}
i = 0;
while( stu[i].b != 0 && stu[i].t != 0 ){
fprintf(fp, "%8d%15d%14s\n",stu[i].b,stu[i].t,stu[i].k);
i++;
}
return 0;
}
書き込みファイル「text.txt」への書き込みは正常に終了
次の課題は書き込んだ「tsxt.txt」からの取り込みですっ |

- >
- Yahoo!サービス
- >
- Yahoo!ブログ
- >
- 練習用



