#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
FILE *fptr;
char name[20];
int score;
fptr=fopen("score.dat","w");
printf("Enter name: ");
scanf("%s",name);
printf("Enter score: ");
scanf("%d",&score);
while(score!=-100){
fprintf(fptr,"%s %d",name,score);
printf("Enter name: ");
scanf("%s",name);
printf("Enter score: ");
scanf("%d",&score);
}
fclose(fptr);
fptr=fopen("score.dat","r");
printf("\n以下是你輸入的data:\n");
while(fscanf(fptr,"%s %d",name,&score)!=EOF){
printf("%-10s %3d\n",name,score);
}
system("pause");
return 0;
}
沒有留言:
張貼留言