程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c語言問題-菜鳥求解(C語言文件讀寫)

c語言問題-菜鳥求解(C語言文件讀寫)

編輯:編程綜合問答
菜鳥求解(C語言文件讀寫)

#include

#include

#include

#include

struct book

{

char name[20];

char phone[20];

char qq[20];

char wechat[20];

};

struct book members[50];

int a,j,k,l,a1,i=0;

char js[10]="y";

char da[20];

char m1[10];

char m2[20];

char m3[20];

char m4[20]="";

int main()

{

FILE * pf;

loop:

printf(" *************************************\n");

printf(" What do you want to do\n");

printf(" 1.creat\n");

printf(" 2.list\n");

printf(" 3.search\n");

printf(" 4.delete\n");

printf(" 5.close\n");

printf(" *************************************\n");

a=getch();

switch(a)

{

case 49 :

pf=fopen("txl.txt","a");

loop2:

printf(" *************************************\n");

printf(" please input information:\n");

printf(" input 'y' to quit when done\n");

printf(" *****************************\n");

printf(" name:");

scanf("%s",members[i].name);

if(strcmp(members[i].name,js)==0)

{

printf(" *****************************\n");

printf(" DATE SAVED\n");

printf(" *****************************\n");

getch();

system("cls");

fclose(pf);

goto loop2;

}

else

{

fprintf(pf,"*************************************\n");

fprintf(pf,"name:%s\n",members[i].name);

printf(" phone:");

scanf("%s",members[i].phone);

fprintf(pf,"phone:%s\n",members[i].phone);

printf(" qq:");

scanf("%s",members[i].qq);

fprintf(pf,"qq:%s\n",members[i].qq);

printf(" wechat:");

scanf("%s",members[i].wechat);

fprintf(pf,"wechat:%s\n",members[i].wechat);

i++;

system("cls");

fclose(pf);

goto loop;

}

case 50 :

pf=fopen("txl.txt","r");

for(a1=0;a1<50;a1++)

{

if(strcmp(m4,members[a1].name)==0)

{

break;

}

printf(" name:%s\n",members[a1].name);

printf(" phone:%s\n",members[a1].phone);

printf(" qq:%s\n",members[a1].qq);

printf(" wechat:%s\n",members[a1].wechat);

printf(" *************************************\n");

}

fclose(pf);

getch();

system("cls");

goto loop;

case 51 :

pf=fopen("txl.txt","r");

printf(" *************************************\n");

printf(" who do you want to find?\n");

printf(" *************************************\n");

printf(" name:");

scanf("%s",m1);

for(j=0;j<1024;j++)

{

if(strcmp(m1,members[j].name)==0)

{

printf(" phone:%s\n",members[j].phone);

printf(" qq:%s\n",members[j].qq);

printf(" wechat:%s\n",members[j].wechat);

getch();

system("cls");

fclose(pf);

goto loop;

}

}

break;

case 52 :

pf=fopen("txl.txt","r+");

printf(" *************************************\n");

printf(" who do you want to delete?\n");

printf(" *************************************\n");

printf(" name:");

scanf("%s",m2);

for(k=0;k<100;k++)

{

if(strcmp(members[k].name,m2)==0)

{

printf(" phone:%s\n",members[k].phone);

printf(" qq:%s\n",members[k].qq);

printf(" wechat:%s\n",members[k].wechat);

printf(" *************************************\n");

printf(" Are you sure(Y OR N):");

scanf("%s",m3);

if(strcmp(m3,js)==0)

{

for(l=k;l<49;l++)

{

members[l]=members[l+1];

}

printf(" *************************************\n");

printf(" This guy has been deleted\n");

printf(" *************************************\n");

getch();

system("cls");

fclose(pf);

goto loop;

}

}

}

case 53 :

pf=fopen("txl.txt","a");

fclose(pf);

}

}

最佳回答:


第一次運行生成的exe文件可以正常錄入信息,txt文件上也有相應的數據,但是第二次打開exe文件數據就全部丟失了

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved