Home > Back-end >  C language singly linked lists recursive output error
C language singly linked lists recursive output error

Time:09-30

C language from the tail end singly linked list recursively output, but the recursive step is always an error, seems to have is to define the problem?

#include
#include
Struct node
{char num [20].
Struct node * link;
};
Typedef node node;

Void main ()
{
NODE * head;
NODE * p;
P=(*) malloc (sizeof (NODE));
P - & gt; The link=NULL;
The head=p;
Printf (" both please enter 5 Numbers separated by new lines: \ n ");
Int the create (NODE * head, int n);
Create (head, 5);
Printf (" the Numbers output: \ n ");
Int the output (the NODE * head);
The output (the head);
}

Int the create (NODE * head, int n)
{
NODE * p;
for(int i=0; I{p=(*) malloc (sizeof (NODE));
Gets (p - & gt; Num);
The head - & gt; The link=p;
The head=p;
}
return 0;
}

Int the output NODE * (head)
{
NODE * p;
P=the head - & gt; The link;
If (p!=NULL & amp; & P - & gt; The link!=NULL)
{
The output (the NODE * p - & gt; Link);
}
If (p!=NULL)
Puts (p - & gt; Num);
return 0;
}

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the Configuration: work4 - Win32 Debug -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Compiling...
Work4. CPP
F: \ Download \ work4 CPP (42) : error C2275: 'NODE' : illegal use of this type as an expression
F: \ Download \ work4 CPP (7) : see declaration of 'NODE'
?? Cl. Exe??? .

Work4. Obj - 1 error (s), and 0 warning (s)

CodePudding user response:

Typedef node node;
Into a typedef struct node node;

CodePudding user response:

 # include 
#include

Struct node
{
Char num [20].
Struct node * link;
};
//typedef node node;
Typedef struct node node;

Int the create (NODE * head, int n);
Int the output (the NODE * head);
Void show (NODE * phead);
//void main ()
Int main ()
{
NODE * head;
NODE * p;
P=(*) malloc (sizeof (NODE));
P - & gt; The link=NULL;
The head=p;
Printf (" both please enter 5 Numbers separated by new lines: \ n ");
//int the create (NODE * head, int n);
Create (head, 5);
//show (the head);
Printf (" the Numbers output: \ n ");
//int the output (the NODE * head);
The output (the head - & gt; Link);
}

Int the create (NODE * head, int n)
{
The NODE * p, * prev.

Prev=head;
for(int i=0; I{
P=(*) malloc (sizeof (NODE));
The fgets (p - & gt; Num, 20, stdin);
Prev - & gt; The link=p;
Prev=p;
}
return 0;
}

Void show (NODE * phead)
{
The NODE * p=phead - & gt; The link;

While (p) {
Printf (" % s \ n ", p - & gt; Num);
P=p - & gt; The link;
}
}

Int the output NODE * (head)
{
If # 1
if (! The head)
return 0;

The output (the head - & gt; Link);
Puts (head - & gt; Num);
# the else
If (p!=NULL & amp; & P - & gt; The link!=NULL)
{
//the output (the NODE * p - & gt; Link);
The output (p - & gt; Link);
}
If (p!=NULL)
Puts (p - & gt; Num);
# endif
return 0;
}


For your reference ~

There is a problem where all did change, for your reference

CodePudding user response:

reference 2 building self-confidence boy reply:
 # include 
#include

Struct node
{
Char num [20].
Struct node * link;
};
//typedef node node;
Typedef struct node node;

Int the create (NODE * head, int n);
Int the output (the NODE * head);
Void show (NODE * phead);
//void main ()
Int main ()
{
NODE * head;
NODE * p;
P=(*) malloc (sizeof (NODE));
P - & gt; The link=NULL;
The head=p;
Printf (" both please enter 5 Numbers separated by new lines: \ n ");
//int the create (NODE * head, int n);
Create (head, 5);
//show (the head);
Printf (" the Numbers output: \ n ");
//int the output (the NODE * head);
The output (the head - & gt; Link);
}

Int the create (NODE * head, int n)
{
The NODE * p, * prev.

Prev=head;
for(int i=0; I{
P=(*) malloc (sizeof (NODE));
The fgets (p - & gt; Num, 20, stdin);
Prev - & gt; The link=p;
Prev=p;
}
return 0;
}

Void show (NODE * phead)
{
The NODE * p=phead - & gt; The link;

While (p) {
Printf (" % s \ n ", p - & gt; Num);
P=p - & gt; The link;
}
}

Int the output NODE * (head)
{
If # 1
if (! The head)
return 0;

The output (the head - & gt; Link);
Puts (head - & gt; Num);
# the else
If (p!=NULL & amp; & P - & gt; The link!=NULL)
{
//the output (the NODE * p - & gt; Link);
The output (p - & gt; Link);
}
If (p!=NULL)
Puts (p - & gt; Num);
# endif
return 0;
}


For your reference ~

There is a problem where all did change, for your reference ~


This is an error, but not the output, and show function is what ah, is the output began to input characters again?

CodePudding user response:

The
reference 1/f, Pacific earth reply:
typedef node node;
Into a typedef struct node node;


Thank you, but also to the following output (p - & gt; Link); Don't complain, but not the output? nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related