Creation is also failing buddy, i got stack dump when i've run this program.
Make play safe with the pointers.

On Sat, Mar 7, 2009 at 2:10 AM, Gaurav <[email protected]> wrote:

>   I have this prog....but it prints only the 1st no....I am unable to
> understand y?
>
> // Link List.
>
> # include<stdio.h>
> # include<stdlib.h>
>
> struct emp
> {
> int eno;
>
> struct emp* next;
> };
> typedef struct emp node;
>
> int main()
> {
> node* create(node *ptr);
> void print(node *ptr);
>
> node *start;
> int ch;
>
> clrscr();
>
> start = NULL;
> while(ch != 3)
> {
> printf("\n 1. Create \n 2. Print: ");
> scanf("%d",&ch);
>
> switch(ch)
> {
> case 1:
> start = create(start);
> break;
> case 2:
> print(start);
> case 3:
> exit(0);
> default:
> printf("\n abc");
> }
> }
> return(0);
> }
>
> node* create(node *start)
> {
> node *temp;
> int n=0;
>
> clrscr();
>
> start = temp = NULL;
>
> while(n!=1)
> {
> printf("\n Enter ENo: ");
> flushall();
> scanf("%d",&n);
> if(start == NULL)
> {
> start = (node*)malloc(sizeof(node));
> start->eno = n;
> start->next = NULL;
> temp = start;
> }
> else
> {
> temp = (node*)malloc(sizeof(node));
> temp->next->eno = n;
> temp->next->next = NULL;
> temp = temp->next;
> }
> }
> return(start);
> }
>
> void print(node *start)
> {
> node *temp;
>
> clrscr();
>
> temp = start;
>
> while(temp != NULL)
> {
> printf("\n %d",temp->eno);
> temp = temp -> next;
> }
> }
>
> 
>



-- 
Cheers,
-nag.


[Non-text portions of this message have been removed]

Reply via email to