Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-08-2008, 08:48 AM   PM User | #1
anis_ahmad
New to the CF scene

 
Join Date: Oct 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
anis_ahmad is an unknown quantity at this point
Netscape stack implementation

I am trying to write a program for stack implementation through linked list but it is giving an error message: "can not convert void * to node *".The code is given below please help to solve my problem.

code:
Code:
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include"malloc.h"
struct node{
int data;
struct node *link;
};
struct node *top;
void main()
{
int will=1,i,numb;
int pop();
void push(int);
void display();
top=NULL;
clrscr();
printf("program for stack linked list demo\n\n");
while(will==1)
{
printf("MAIN MENU\n\n 1. push insert element on the stack\n 2. pop delete item from stack\n");
scanf("%d",&will);
switch(will)
{
case 1:
printf("enter the data....\n");
scanf("%d",&numb);
push(numb);
display();
break;
case 2:
i=pop();
printf("returned value from pop is %d\n",i);
break;
default:
printf("invalid choice\n ");
}
printf("do you want to continue \n" " 1 for yes and any other key to exit\n");
scanf("%d",&will);
}
}
void push(int y)
{
struct node *x;
x=malloc(sizeof(struct node));
printf("address of newly created node is %d",x);
x->data=y;
x->link=top;
top=x;
}
void display()
{
int i=0;
struct node *temp;
temp=top;
while(temp!=NULL)
{
printf("Item no. is %d : Data %d Link %d",i++,temp->data,temp->link);
temp=temp->link;
}
}
int pop()
{
int a;
if(top==NULL)
{
printf("stack empty\n");
return 0;
}
else
{
a=top->data;
printf("the returned value is %d",a);
free(top);
top=top->link;
return(a);
}
}

Last edited by oracleguy; 10-08-2008 at 07:33 PM..
anis_ahmad is offline   Reply With Quote
Old 10-08-2008, 07:33 PM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
I assume you haven't solved your problem and removed the resolve flag on your thread.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:03 PM.


Advertisement
Log in to turn off these ads.