[ create a new paste ] login | about

Link: http://codepad.org/ZpASkiow    [ raw code | output | fork ]

C, pasted on Nov 9:
#include<stdio.h>
#include<afxcoll.h> //use the "collection" class
#include<malloc.h>


typedef struct{
  CPtrList lst;

} STACK;

void push(STACK *s, int *data){
  (*s).lst.AddHead((void *) data);
}

int *pull(STACK * S)
{
  int * result;
  result =(int *)(*s).lst.GetHead();
   (*s).lst.RemoveHead();
   return result;
}

BOOL isEmpty(STACK *s)
{
  return(*s).lst.IsEmpty();
}

void main()
{
   int * aNumber;
   STACK myStack;
   STACK * P = &myStack;
//  create 5 new integers dynamically and push the corresponding pointers
//  to the stack.
//
    for(int i=0; i<5; i++){
	aNumber=(int *)malloc(sizeof(int));
	*aNumber=i;
	push(p, aNumber);
	printf("%d pushed on stack\n", *aNumber);

}

   printf("\nPop data from stack:\n");
   while(!isEmpty(p))
   {
     aNumber = pull(p);
	 printf("%d pulled from stack\n", *aNumber);
     free(aNumber);
   }
   printf("Stack is empty.\n");

}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Line 48: error: afxcoll.h: No such file or directory
Line 7: error: expected specifier-qualifier-list before 'CPtrList'
In function 'push':
Line 12: error: 'STACK' has no member named 'lst'
In function 'pull':
Line 18: error: 's' undeclared (first use in this function)
Line 18: error: (Each undeclared identifier is reported only once
Line 18: error: for each function it appears in.)
t.c: At top level:
Line 23: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'isEmpty'
In function 'main':
Line 36: error: 'for' loop initial declaration used outside C99 mode
Line 39: error: 'p' undeclared (first use in this function)
Line 29: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: