Why i always get the address of the number??
2295367 >_<

#include<stdio.h>
#include<stdlib.h>
#define p printf
#define s scanf
#include<ctype.h>
struct node
{
int data;
struct node *link;
};typedef struct node *nodepointer;
void push(nodepointer &top,int number)
{
nodepointer newnode,temp;
newnode=(nodepointer)malloc(sizeof(struct node));
newnode->data=number;
newnode->link=NULL;
if(top==NULL)
{
top=newnode;
}
else
{
temp=top;
while(temp->link!=NULL)
temp=temp->link;
temp->link=newnode;
}do
{
p("\nEnter number: ");
fflush(stdin);
s("%i",&number);
}while(isalpha(number));
}
void display(nodepointer top)
{
if(top==NULL)
{
p("\nNothing to display");
}
else if(top!=NULL)
{
while(top->link!=NULL)
{
p("\n%i",top->data);
top=top->link;
}
p("\n%i",top->data);
}
}
main()
{
nodepointer top;
top=NULL;
int number;
int choice;
int found;
char operators;
do
{
p("\n[1].Push");
p("\n[2].Display");
p("\n[3].Add operator");
p("\nKey choice: ");
fflush(stdin);
s("%i",&choice);
switch(choice)
{
case 1:
push(top,number);
break;
case 2:
display(top);
}
}while(1==1);
system("pause");
}

You were passing in number to the push function and setting the node->data to that value which was some random value coming off of the stack. Take a look at the changes I made, I put comments in to explain.

#include<stdio.h>
#include<stdlib.h>
#define p printf
#define s scanf
#include<ctype.h>

struct node
{
  int data;
  struct node *link;
};

typedef struct node * nodepointer;

// Removed the number because that is not what you 
// want to do.  Declare a local number variable inside
// this function to read the real value of number into.
// You also want to pass a pointer to a pointer to a
// node.
//void push(nodepointer &top, int number) {
void push(nodepointer *top) {
  nodepointer newnode,temp;
  int number;
  newnode=(nodepointer)malloc(sizeof(struct node));
  //newnode->data=number;    // <--------- Moved to down below
  newnode->link=NULL;
  if(*top==NULL) {
    *top=newnode;
  }
  else {
    temp=*top;
    while(temp->link!=NULL)
      temp=temp->link;
    temp->link=newnode;
  }
  do {
    p("\nEnter number: ");
    fflush(stdin);
    s("%i",&number);
  }while(isalpha(number));
  newnode->data=number;    // <--------- Need to set the value here!
}

void display(nodepointer top) {
   if(top==NULL) {
      p("\nNothing to display");
    }
    else if(top!=NULL) {
      while(top->link!=NULL) {
         p("\n%i",top->data);
         top=top->link;
      }
      p("\n%i",top->data);
   }
}

int main() {
   nodepointer top;
   top=NULL;
   int number;
   int choice;
   int found;
   char operators;
   do {
      p("\n[1].Push");
      p("\n[2].Display");
      p("\n[3].Add operator");
      p("\nKey choice: ");
      fflush(stdin);
      s("%i",&choice);
      switch(choice) {
         case 1:
            // You want to pass a pointer to a pointer, so the & goes here.
            // Don't need to pass number here.
            //push(&top,number);   <-------- This number is not used
            push(&top); 
            break;
         case 2:
            display(top);
      }
   }while(1==1);
}

Output:

$ ./a.out

[1].Push
[2].Display
[3].Add operator
Key choice: 1

Enter number: 1

[1].Push
[2].Display
[3].Add operator
Key choice: 1

Enter number: 2

[1].Push
[2].Display
[3].Add operator
Key choice: 1

Enter number: 3

[1].Push
[2].Display
[3].Add operator
Key choice: 2

1
2
3
[1].Push
[2].Display
[3].Add operator
Key choice: ^C
$
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.