Home > Back-end >  Who teach, why always runtime error
Who teach, why always runtime error

Time:06-04

/* a known structure are defined as follows: struct employee {int id;//gonghaowu char name [20];//name int salary;//struct pay the employee * next; }; Assume that has established an ascending order according to the salary value chain table (no special head node), request program, implement new nodes insertion function, a new node inserted into the list of salary value remains ascending, sub function should contain nodes of the memory needed to apply for and staff information input function, input a ascending order according to the salary value chain table and insert the new node information, establish a linked list, continuous type node information (including job number, name, salary (salary>=0)) and data types as shown in the above structure, the list ended up with salary for 1, continue to type in a line of inserting new node information, specific see sample format, */# include
# include
# define L sizeof (struct employee)
Struct the employee {
Int id;
Char name [20].
Int salary;
Struct the employee * next; };
Struct the employee * creat (void);
Void print (struct the employee * head);
Struct the employee * h (struct the employee * e1, struct the employee * e2);
int n;
Int main () {
Struct the employee * e1, e2,
E1=creat ();
E2=(struct the employee *) malloc (L); The scanf (" % d % d % s ", & amp; E2 - & gt; Id, e2 - & gt; The name, & amp; E2 - & gt; Salary); E2 - & gt; Next=NULL;
Printf (" the all employee information: \ n "); Print (h (e1 and e2)); }
Struct the employee * creat (void) {
Head, struct the employee * * p1, * p;
n=0;
P=(struct the employee *) malloc (L); The scanf (" % d % d % s ", & amp; P - & gt; Id, p - & gt; The name, & amp; P - & gt; Salary); While ((p - & gt; Salary)!={
(1))N=n + 1;
If (n==1) head=p;
The else p1 - & gt; Next=p;
P1=p;
P=(struct the employee *) malloc (L); The scanf (" % d % d % s ", & amp; P - & gt; Id, p - & gt; The name, & amp; P - & gt; Salary); P1} - & gt; Next=NULL;
Free (p);
return(head); }
Void print (struct the employee * head) {
Struct the employee * t;
T=head;
Do {printf (" % d % d % s \ n ", t - & gt; Id, t - & gt; The name, t - & gt; Salary); T=t - & gt; Next; } while (t!=NULL); }
Struct the employee * h (struct the employee * e1, struct the employee * e2) {
Q, struct the employee * * o; O=NULL;
Q=e1;
While (q!=NULL) {
If ((e2 - & gt; Salary) & gt; (q - & gt; Salary)) {
O=q;
Q=q - & gt; Next; }
The else
break; }
If (o==NULL) {
E2 - & gt; Next=e1;
Return (e2); }
The else {o - & gt; Next=e2; E2 - & gt; Next=q; Return (e1); }}

CodePudding user response:

The error C4703: using an uninitialized pointer variable local may have "head"
The error C4703: using an uninitialized pointer variable local may have "p1"

CodePudding user response:

I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related