Re: Linked list, no out put,help



* 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?
.



Relevant Pages

  • radix sort
    ... struct node *next; ... void freelist; ... int large_dig; ... kth digit of all no:s */ ...
    (comp.programming)
  • LinkedList Pointer (REPOST - diff version)
    ... struct node * next; ... No problem until you are dealing with a pointer variable. ... void Push(struct node** headRef, int newData); ... Given an int and a reference to the head pointer (i.e. a struct ...
    (comp.lang.c)
  • LinkedList Pointer (REPOST - diff version)
    ... struct node * next; ... No problem until you are dealing with a pointer variable. ... void Push(struct node** headRef, int newData); ... Given an int and a reference to the head pointer (i.e. a struct ...
    (comp.lang.c)
  • Re: free memory question
    ... pointer (ptr) dynamically allocated in function "test_free"? ... struct node* y; ... int main ... struct node* calc = NULL; ...
    (comp.lang.c)
  • qsmurf.c
    ... Commenting out the printfthat is called for each packet that is sent. ... sends to the Quake server, so about half the bandwidth is being used to tell you that each packet was sent. ... struct node *next; ... void sig_handler(int); ...
    (Bugtraq)