My assignment says :
Write a program to perform following stack operations : Create a stack with item code and quantity
Itemcode Quantity
111 450
112 0
113 487
114 101
115 500
116 0
117 359
and then Delete the items having quantity zero and update the stack.
My code is :
#include<stdio.h>
#define LEN 7
struct item { int* num ; int* q; }
int main(void){
int length = LEN,i,j;
struct item data[LEN];
// read input data into struct
for(i=0 ; i < LEN ; i++){
printf(" %d . enter item-code : ",i);
scanf("%d",data[i].num);
printf(" %d . enter quantity : ",i);
scanf("%d",data[i].num);
}
// Delete the items having quantity zero and update the stack
for(i=0 ; i < length ; i++) if(*data[i].q == 0){
for(j=i+1;j<length;j++)
data[j-1] = data[j]; // update by overwriting
data[j] = NULL;
length--;
}
// display stack
for(i=0 ; i < length && data[i]!= NULL; i++){
printf(" %d > item : %d , quantity : %d\n",i,*data[i].num,*data[i].q);
}
return 0;
}
Its the 1st time i'm working with structs in C . The errors i get are :
StructStack.c:5: error: two or more data types in declaration specifiers
StructStack.c: In function 'main':
StructStack.c:21: error: incompatible types when assigning to type 'struct item' from type 'void *'
StructStack.c:26: error: invalid operands to binary != (have 'struct item' and 'void *')
StructStack.c:30: error: incompatible types when returning type 'int' but 'struct item' was expected
Any help would be great.
regards
Somjit.