Home > Back-end >  Turn to the same code should not be run twice
Turn to the same code should not be run twice

Time:12-25

 # include & lt; stdio.h> 
# include & lt; Stdlib. H>
Typedef struct node {
The int value.
struct node* next;
} the node;
Int main (void)
{

Node * head=(*) malloc (sizeof (node));
Node * begin=head;
Scanf_s (" % d ", & amp; The begin - & gt; Value);
While (the begin - & gt; The value!=0);
{
The begin - & gt; Next=(*) malloc (sizeof (node));
The begin=the begin - & gt; next;
Scanf_s (" % d ", & amp; The begin - & gt; Value);
}
The begin - & gt; Next=NULL;
The begin=head;
While (the begin!=NULL) {
Printf (" % d ", the begin - & gt; Value);
The begin=the begin - & gt; next;
}
return 0;
}


After enter a digital press enter to subsequent operation is the same code so that the second time is bad also make just now

CodePudding user response:

See behind while the semicolon, nor should it just that,

CodePudding user response:

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

Typedef struct node {
The int value.
struct node* next;
} the node;

Int main (void)
{

Node * head=(*) malloc (sizeof (node));
Node * begin=head;
Scanf_s (" % d ", & amp; The begin - & gt; Value);
//while (the begin - & gt; The value!=0);
While (the begin - & gt; The value!=0)
{
The begin - & gt; Next=(*) malloc (sizeof (node));
The begin=the begin - & gt; next;
Scanf_s (" % d ", & amp; The begin - & gt; Value);
}
The begin - & gt; Next=NULL;
The begin=head;
While (the begin!=NULL) {
Printf (" % d ", the begin - & gt; Value);
The begin=the begin - & gt; next;
}
return 0;
}

For your reference ~
  • Related