Aug 30, 2013 at 8:50pm Aug 30, 2013 at 8:50pm UTC
my code is:
#include<stdio.h>
#include<iostream.h>
struct node
{
int info;
struct node *next;
};
typedef struct node *nodeptr;
nodeptr i;
nodeptr q;
nodeptr p;
nodeptr *plist;
nodeptr getnode(void)
{
nodeptr p;
p=(nodeptr)malloc(sizeof(struct node));
return p;
}
void freenode(nodeptr p)
{
free(p);
}
int main()
{
int i;
nodeptr *k;
int a;
int r;
nodeptr end;
p=getnode();
q=getnode();
for(i=0; i<3; i++)
{
q=*k;
cout<<"enter value";
cin>>r;
p->info=r;
q->next=p;
q=q->next;
}
for(q=*k; q->next!=NULL; q=q->next)
cout<<(q->next)->info;
return 0;
}
here when i input three nos
in the output the last no is only shown
can yu suggest me what is wrong in the code
please help
Aug 31, 2013 at 5:47am Aug 31, 2013 at 5:47am UTC
Get out of the habit of using global variables. It may not seem like a bad thing now, and it probably isn't in a small program like this, but trust me, it's not a good thing to use. Better to have getters and setters than have anything in global scope.