Re: Linked list, no out put,help
- From: "Alf P. Steinbach" <alfps@xxxxxxxx>
- Date: Fri, 30 Jun 2006 13:34:04 +0200
* asm_fool@xxxxxxxxxxx:
dear group,
/*Linked list in C*/
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}a;
void init(int data)
{
struct node *p;
p = malloc(sizeof *p);
if(!p)
{
printf("mem error");
exit(EXIT_FAILURE);
}
a.data = data;
a.next = NULL;
p = &a;
}
int main(void)
{
unsigned int i,j;
for(j=0;j<6;j++)
{
scanf("%d",&i);
init(i);
}
while(a.next != NULL)
{
for(j=0;j<6;j++)
printf("value = %d\n",a.data);
}
return 0;
}
This is not the first time I am implementing a linked list.But every
time I
try to do that I get no out put. The above is the same situation. The
above
don't print any out put. Can any one tell me why.
In your 'init' function you set 'a.next = NULL'. The continuation condition for your output loop is 'a.next != NULL'. That condition evaluates to 0 the first time, and the loop body is never executed.
[OT]
I can not configure news reader in my company. Same with the mail
reader. Though I use win98 the pop and nntp server simply functioning.
So I go for the ugly google. [/OT]
Do you actually work in a company? This is not professional code. It's student code.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.
- References:
- Linked list, no out put,help
- From: asm_fool
- Linked list, no out put,help
- Prev by Date: Scope of specifier extern
- Next by Date: Re: Linked list, no out put,help
- Previous by thread: Linked list, no out put,help
- Next by thread: Re: Linked list, no out put,help
- Index(es):
Relevant Pages
|