F
fool
Dear group,
Thanks for all those who helped previously.
Now I get some value printed. Is that the value of the list getting
printed? Am I
really polluted the list?
Previous thread link (sorry for google)
http://groups.google.com/group/comp...b772b/578ac16a2ed4ed35?hl=en#578ac16a2ed4ed35
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *add_node(struct node *p, int funct_data)
{
struct node *t = p;
/* passed by values. So I save the argument value in a
* temp variable.Am I correct?*/
t = malloc(sizeof *t);
if(!t)
{
printf("mem error");
exit(EXIT_FAILURE);
}
t->data = funct_data;
return t;
}
int main(void)
{
struct node *p,*q;
int i;
q=malloc(sizeof *q);
if(!q)
exit(EXIT_FAILURE);
for(i=0 ; i< 6 ; i++)
{
q = add_node(p, i);
printf("%d\n",q->data);
}
return 0;
}
Thanks for all those who helped previously.
Now I get some value printed. Is that the value of the list getting
printed? Am I
really polluted the list?
Previous thread link (sorry for google)
http://groups.google.com/group/comp...b772b/578ac16a2ed4ed35?hl=en#578ac16a2ed4ed35
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *add_node(struct node *p, int funct_data)
{
struct node *t = p;
/* passed by values. So I save the argument value in a
* temp variable.Am I correct?*/
t = malloc(sizeof *t);
if(!t)
{
printf("mem error");
exit(EXIT_FAILURE);
}
t->data = funct_data;
return t;
}
int main(void)
{
struct node *p,*q;
int i;
q=malloc(sizeof *q);
if(!q)
exit(EXIT_FAILURE);
for(i=0 ; i< 6 ; i++)
{
q = add_node(p, i);
printf("%d\n",q->data);
}
return 0;
}