For replacing numbers in my variable expression , I wrote a program to get the expression with variables , and for each variable I read the number value from the user and replace it.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
char *OPRND_Stack = NULL;
int main()
{
// getting postfix string
char postfix[40];
printf("Enter the postfix expression: ");
scanf("%s",postfix);
int postfix_length = strlen(postfix);
printf("Enter the value of: \n");
int arrayIndex = 0;
char temp;
while(postfix[arrayIndex] != '\0')
{
if(isalpha(postfix[arrayIndex]))
{
printf("%c : ",postfix[arrayIndex]);
scanf("%c",&temp);
postfix[arrayIndex] = temp;
}
arrayIndex++;
}
printf("\nTransformed Expression : %s",postfix);
}
The output is
Enter the postfix expression: ab+c+
Enter the value of:
a : b : 3
c :
Transformed Expression :
3+
+
But i should get like this,
ab+c+
a : 5
b : 3
c : 2
Transformed expression : 53+2+
What is the mistake i had done or what might be the cause for skipping my input and assigning new line as its value.