2045 1
Want to convert infix to postfix in C but getting error empty stack

I write a C code to convert infix expression to postfix expression. The expression may include '^' , "+", "-" , "/", "*" and all three types of brackets i.e." ({[ ". The code should first check whether the brackets are balanced or not and then do the conversion. But the code is showing an empty stack at the output.

Here is my sample code

...
Type
Question
1448 1
Can anybody help me to convert a infix expression into a postfix expression which deals with all three brackets i.e. ({[ in c language?

This is the pseudo code. Create a function that takes an infix expression as input and converts it to a postfix expression. It should  

take pointers to two strings as input; one containing the infix expression, and second to which this

function will write the postfix expression i.e. the declaration should be

void infixToPostfix(char *infix, char *postfix, int str_size);

The algorithm is as follows:

Iterate over the infix expression’s string. For each character c,

• If c is an operand, concatenate it with the postfix expression.

• If c is an operator, check if top of stack, say m, is an operator. If so, check if the operator

precedence of m is higher or equal to the operator precedence of c; if yes, concatenate m with

postfix expression, and pop it from the stack. Keep doing this until the top of stack is not an

operator with operator precedence higher or equal to the operator precedence of c. Then push

c on the stack.

• After completely processing input expression, TopAndPop remaining operators from stack and

concatenate each with postfix expression, in the order they are popped.

You can perform string concatenation using strcat().

...
Type
Question
1264 0
C Program to print Fibonacci Triangle
Fibonacci Series is one of the most asked questions in Tech Interviews. Here, I have attempted to simplify the explanation with the help of an example.
Type
Article
657 1
Not understanding what happens in memory during dynamic memory allocation using pointers in C?

#include<stdio.h>

#include<stdlib.h>

int main()

{

    int *p;

    p=(int *) malloc(4);

    if(p==NULL)

    {

        printf("Insufficient memory");

        return;

 

    }

    printf("Enter a number\n");

    scanf("%d",p);

 

    printf("Value of p=%d",*p);

 

}

 

1) What happens in background when we do int *p? Can you show a figure about what it does in memory?

 

2) What happens in memory "p=(int *) malloc(4);" when we run this line? In surface, I've rote memorized, it allocates 4 bytes of memory, but I don't know in detail what happens in background.

 

3) printf("Enter a number\n");

    scanf("%d",p);

 

I need to store a number in address of p, so should not I do &p instead of just p?

 

4) Value of p=p isn't it? Why *p? I've again rote memorized *p gives value of p, but I'm not clear about what's going inside memory during this all.

 

I'm asking these questions knowing I'm wrong because I've tested the code in codeblocks already. It's not to get the correct answer but a way to think to get a correct answer.

 

If we'd done;

int x=10;

int *p=&x;

I'd understand what's being done here.

It means content of p is initialzed with address of x. Like this:

https://imgur.com/a/7BNzsGO

but I don't understand the above case that I mentioned in question where we are only doing int *p. I find it meaningless. p is a pointer variable. But it contains whose address?

...
Type
Question
293 1
Write a C program for the following pyramid * * * * * *
  • * * * * * *
  • * * * * *
  • * * * *
  • * * *
  • * *
  • *
  • * *
  • * * *
  • * * * *
  • * * * * *
  • * * * * * *
...
Type
Question

Page 4 of 4