将通讯录实现成文件存储的版本。

将通讯录实现成文件存储的版本。


#include<stdio.h>
#include<Windows.h>
#include<stdlib.h>


#pragma warning (disable:4996)




int main(){
char name[100];
int age;
char tel[100];
int i = 0;
FILE *pfile;
pfile = fopen("people.txt", "w");
if (pfile == NULL){
perror("fopen");
return 1;
}


for (; i < 5; i++){
printf("name:");
fscanf(stdin, "%s", &name);
printf("age:");
fscanf(stdin, "%d", &age);
printf("tel:");
fscanf(stdin, "%s", &tel);
fprintf(pfile, "name:%s\t    age:%d\t   tel:%s\t  \n",name,age,tel);
}
fclose(pfile);
system("pause");
return 0;




}



猜你喜欢

转载自blog.csdn.net/sd116460/article/details/80589014