Home > Back-end >  C language, the establishment of a file, to input data to the data in the file, but I don't kno
C language, the establishment of a file, to input data to the data in the file, but I don't kno

Time:10-10

In the form of a list to input data file, a set of information, and then thinking about writing a output function to see if the input
Went in, as a result, compile operation shows nothing, but it's ok to compile, don't know where the code
Out the problem, want to consult everybody a great god help to look at the code, and see where there is any problem, the time was a little
Be urgent!!!! In this thank you!!!!!!!!!!
 # include & lt; stdio.h> 
#include
#include


The structure of the struct acc_message//define node
{char name [12].
Int cardnum;
Int the password;
Double acc_balance;
Struct acc_message * next;
};

Int main ()
{
Struct acc_message * head;//create an empty list
The head=(struct acc_message *) malloc (sizeof (struct acc_message));
The head - & gt; Next=NULL;
Struct acc_message * p, * q;
Q=head;


The FILE * fp.//set up the original bank customer information file
If ((fp=fopen (" message. TXT ", "wt +"))==NULL) {
Printf (" Open this file error, press any key to exit!/n ");
getchar();
exit(0);
}
int i=0;
While (i<5) {
P=(struct acc_message *) malloc (sizeof (struct acc_message));//create a new node
If (p==NULL) break;
The switch (I)
{case 0:
Fprintf (fp, "Jane, 62221111, 123456, 8000/n", p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
Case 1:
Fprintf (fp, "Alan, 62221112, 123456, 500/n", p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
Case 2:
Fprintf (fp, "Mary, 62221113, 123456, 600000/n", p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
Case 3:
Fprintf (fp, "Alice 62221114 123456 0/n", p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
Case 4:
Fprintf (fp, "Kivin, 62221115, 123456, 70000/n", p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
}
Q - & gt; Next=p;
Q=p;
i++;
}
Q - & gt; Next=NULL;
The rewind (fp);

Struct acc_message * r=head - & gt; Next;
While (r!=NULL) {
Fscanf (fp, "% s % d % d % d/n", r - & gt; The name, r - & gt; Cardnum, r - & gt; Password, r - & gt; Acc_balance);
R=r - & gt; Next;
}
The fclose (fp);

}

CodePudding user response:

 # include & lt; stdio.h> 
#include
#include


The structure of the struct acc_message//define node
{char name [12].
Int cardnum;
Int the password;
Double acc_balance;
Struct acc_message * next;
};

Int main ()
{
Struct acc_message * head;//create an empty list
The head=(struct acc_message *) malloc (sizeof (struct acc_message));
The head - & gt; Next=NULL;
Struct acc_message * p, * q;
Q=head;


The FILE * fp.//set up the original bank customer information file
If ((fp=fopen (" message. TXT ", "wt +"))==NULL) {
//printf (" Open this file error, press any key to exit!/n ");
Printf (" Open this file error, press any key to exit! \ n ");
getchar();
exit(0);
}
int i=0;
While (i<5) {
P=(struct acc_message *) malloc (sizeof (struct acc_message));//create a new node
If (p==NULL) break;
The switch (I)
{
Case 0:
//fprintf (fp, "Jane, 62221111, 123456, 8000/n", p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
Fprintf (fp, "Jane, 62221111, 123456, 8000 \ n");//p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
Case 1:
Fprintf (fp, "Alan, 62221112, 123456, 500 \ n");//p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
Case 2:
Fprintf (fp, "Mary, 62221113, 123456, 600000 \ n");//p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
Case 3:
Fprintf (fp, "Alice 62221114 123456 0 \ n");//p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
Case 4:
Fprintf (fp, "Kivin, 62221115, 123456, 70000 \ n");//p - & gt; The name, p - & gt; Cardnum, p - & gt; Password, p - & gt; Acc_balance);
break;
}
Q - & gt; Next=p;
Q=p;
i++;
}
Q - & gt; Next=NULL;
The rewind (fp);

Struct acc_message * r=head - & gt; Next;
While (r!=NULL) {
//fscanf (fp, "% s % d % d % d/n", r - & gt; The name, r - & gt; Cardnum, r - & gt; Password, r - & gt; Acc_balance);
Fscanf (fp, "% s % d % d % lf \ n", r - & gt; The name, & amp; R - & gt; Cardnum, & amp; R - & gt; Password, & amp; R - & gt; Acc_balance);
R=r - & gt; Next;
}

R=the head - & gt; Next;
While (r) {
Fprintf (stdout, "% s % d % d % lf \ n", r - & gt; The name, r - & gt; Cardnum, r - & gt; Password, r - & gt; Acc_balance);
R=r - & gt; Next;
}
The fclose (fp);

}


For your reference ~

No any output, then because the building no output,

Other issues, the code can be found in the above code;
  • Related