Home > Back-end >  The scanf is not implemented in the while loop? Is why?
The scanf is not implemented in the while loop? Is why?

Time:12-09

int n;
Struct Student * creat (void) {
Struct Student * head;
P1 struct Student * * (p2);
N=0;
P1=p2=(struct Student *) malloc (LEN);
the scanf (" % f, % 1 d ", & amp; P1 - & gt; Num, & amp; P1 - & gt; Score);
The head=NULL;
While (p1 - & gt; Num!=0) {
N=n + 1;
If (n==1) head=p1;
The else p2 - & gt; Next=p;
P1 p2=;
P1=(struct Student *) malloc (LEN);
the scanf (" % f, % 1 d ", & amp; P1 - & gt; Num, & amp; P1 - & gt; Score);
}
The p2 - & gt; Next=NULL;
Return (the head);
}

The first to enter the scanf is normal, but the second can't, the second the scanf debugging, is directly in the past, cannot perform the function of the input, is this why??

CodePudding user response:

Tracking debugging is the basic skill,

CodePudding user response:

Search for tracking debugging, it would be easy to find the problem,

CodePudding user response:

Before the second the scanf perform the fflush (stdin), but also recommend you to have a look at the debugging technique
https://edu.51cto.com/sd/c4099

CodePudding user response:

Good
  • Related