70,024
社区成员




#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct acc_message //定义结点的结构
{ char name[12];
int cardnum;
int password;
double acc_balance;
struct acc_message *next;
} ;
int main()
{
struct acc_message *head; //创建空链表
head =(struct acc_message*)malloc(sizeof (struct acc_message));
head -> next =NULL ;
struct acc_message *p, *q ;
q = head ;
FILE *fp; //建立原有银行客户信息文件
if ((fp = fopen("message.txt","wt+"))==NULL){
printf("Open this file error,press any key exit!/n ");
getchar();
exit(0);
}
int i=0;
while(i<5){
p =(struct acc_message*)malloc(sizeof (struct acc_message)); //创建新节点
if (p==NULL) break;
switch (i)
{ case 0:
fprintf (fp,"Jane 62221111 123456 8000/n",p->name,p->cardnum,p->password,p->acc_balance);
break;
case 1:
fprintf (fp,"Alan 62221112 123456 500/n",p->name,p->cardnum,p->password,p->acc_balance);
break;
case 2:
fprintf (fp,"Mary 62221113 123456 600000/n",p->name,p->cardnum,p->password,p->acc_balance);
break;
case 3:
fprintf (fp,"Alice 62221114 123456 0/n",p->name,p->cardnum,p->password,p->acc_balance);
break;
case 4:
fprintf (fp,"Kivin 62221115 123456 70000/n",p->name,p->cardnum,p->password,p->acc_balance);
break;
}
q -> next=p;
q=p;
i++;
}
q->next = NULL;
rewind (fp);
struct acc_message *r = head->next;
while (r!=NULL){
fscanf(fp,"%s %d %d %d/n",r->name,r->cardnum,r->password,r->acc_balance);
r=r->next;
}
fclose(fp);
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct acc_message //定义结点的结构
{ char name[12];
int cardnum;
int password;
double acc_balance;
struct acc_message *next;
};
int main()
{
struct acc_message *head; //创建空链表
head =(struct acc_message *)malloc(sizeof (struct acc_message));
head-> next = NULL ;
struct acc_message *p, *q ;
q = head ;
FILE *fp; //建立原有银行客户信息文件
if ((fp = fopen("message.txt","wt+"))==NULL){
//printf("Open this file error,press any key exit!/n ");
printf("Open this file error,press any key exit!\n ");
getchar();
exit(0);
}
int i=0;
while(i<5){
p =(struct acc_message*)malloc(sizeof (struct acc_message)); //创建新节点
if (p==NULL) break;
switch (i)
{
case 0:
//fprintf (fp,"Jane 62221111 123456 8000/n",p->name,p->cardnum,p->password,p->acc_balance);
fprintf (fp,"Jane 62221111 123456 8000\n");//, p->name,p->cardnum,p->password,p->acc_balance);
break;
case 1:
fprintf (fp,"Alan 62221112 123456 500\n");//,p->name,p->cardnum,p->password,p->acc_balance);
break;
case 2:
fprintf (fp,"Mary 62221113 123456 600000\n");//,p->name,p->cardnum,p->password,p->acc_balance);
break;
case 3:
fprintf (fp,"Alice 62221114 123456 0\n");//,p->name,p->cardnum,p->password,p->acc_balance);
break;
case 4:
fprintf (fp,"Kivin 62221115 123456 70000\n");//,p->name,p->cardnum,p->password,p->acc_balance);
break;
}
q -> next=p;
q=p;
i++;
}
q->next = NULL;
rewind (fp);
struct acc_message *r = head->next;
while (r!=NULL){
//fscanf(fp,"%s %d %d %d/n",r->name,r->cardnum,r->password,r->acc_balance);
fscanf(fp,"%s %d %d %lf\n",r->name, &r->cardnum, &r->password, &r->acc_balance);
r=r->next;
}
r = head->next;
while (r) {
fprintf(stdout,"%s %d %d %lf\n", r->name, r->cardnum, r->password, r->acc_balance);
r = r->next;
}
fclose(fp);
}