So I am trying to make a infix to postfix program in C but when I start entering the symbols, the loop ends at the first entry.
I am pretty sure it's a data type problem somewhere but I can't figure out where..
Here is the code:
#include <stdio.h>
#include <stdlib.h>
static int N;
static char *s;
void stackinit(int max){
s = malloc(max*sizeof(int));
N = 0;
}
int stackempty(){
if(N==0)
return(1);
else
return(0);
}
void stackpush(char item){
s[N] += item;
N++;
}
int stackpop(){
N--;
return(s[N]);
}
int priority(char x){
if(x == '+' || x == '-')
return(0);
if(x == '*' || x == '/')
return(1);
}
int main(void){
int i,sum;
char input;
printf("Infix to Postfix\n");
printf("How many characters will you enter?");
scanf("%d", &sum);
stackinit(sum);
for(i = 0; i < sum; i++){
printf("Enter character: ");
scanf("%s", &input);
stackpush(input);
}
while(!stackempty()){
printf("%d ", stackpop());
}
/*for(i = 0; i < sum; i++){
}*/
}