spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Output shows un common characters while changing from infix to postfix notation using C++


The problem is that you process p_newStr without initializint it, and only performing pointer arithmetic on it. I guess, that you wanted to see it as a string, adding chars to it.

So first initialisze it:

    char* p_newStr = newStr; // It was
unitinitalised, pointing at random location

Then note that p_newStr = p_newStr + str[i] means adding the value of the char str[i], converted to int, to the pointer p_newStr. That's pointer arithmetic. Replace this statement with:

    *p_newStr++ = str[i];   // instead
of p_newStr = ... 

and there is another one taking a char from the stack[]:

    *p_newStr++ = stack[top];   //
instead of p_newStr = ... 

Finally, put an ending null terminator to the c string you've built, just before your printf():

    *p_newStr++ = 0;

Once these corrections made, the code produces exactly the expected results.


Categories : C

Related to : Output shows un common characters while changing from infix to postfix notation using C++
infix to postfix with white space
Well first off, I wasn't able to compile your code due to this line int top = -1; void push(char elem) { s[++top] = elem; } It's very dangerous to initialize your arrays using a variable that's negative. When we go to pop() the character symbols in the array, it will return to its initial state at top = -1 which causes the compilation error. My suggestion is to change your code around to some

Categories : C
Convert Infix to Postfix with Binary Tree
It looks like the easiest way to convert the expression from infix to postfix notation is to use a standard stack based algorithm(it has linear time complexity, so it is optimal) and then to build a tree(constructing a tree from postfix expression is simple because all operators are in a correct order).

Categories : C#
infix to postfix with logical operators - code error
HasHigherPrecedence(op1, op2) is expected to return non-zero when op1 has a higher precedence (A.K.A. weight) than op2 and zero otherwise. However it returns the maximum of the two ops' weights, which is usually nonzero. You just need to change the function so it returns: return op1Weight > op2Weight; Which will be 1 when true and zero when false. This should fix your operator shunting.

Categories : C++
SQL query to return most common, 2nd most common, 3rd most common occurrences
You can just use GROUP_CONCAT() aggregate function: SELECT Fruit, GROUP_CONCAT(Freshness ORDER BY cnt DESC) as Common FROM ( SELECT Fruit, Freshness, COUNT(*) cnt FROM fruits GROUP BY Fruit, Freshness ) s that will return values like: Fruit | Common --------------------- Banana | New,Old,Ripe Cherry | New,Ripe ... | ... but if you want to divide the result in three column

Categories : Mysql
Unexpected characters in console output
According to C++ Reference, you are right. As pointed out in the comments, for the string implementation you use, the arguments are switched. For the second example, you print the sign (111-1)/2 = 55 = '7' for ' ' = 32 times. Swap the arguments to string(' ',(111 - s.length()) / 2) and it should work better.

Categories : C++
Recently Add
Issues with sorting using doubly linked list
Fatal error while printing a 2 dimensional array
What is the pointer pointing to?
Generating a Sudoku Board in C
reading words/strings from file+length of them - c
Is my interpretation correct?Can I print binary representation for double, as eg:1?
order of evaluation for multiple increment operator on pointer
Looking for algorithm to find n unset bits in a bitset
Pthreads - Increase maximum number of read locks
Write one billion files in one Folder BUT "(No space left on device)" error
Compiler doesn't stop on scanf() for input
Line Counter In C
Reasigning a pointer?
The last character is not printed to a file
How do I empty the SDL event queue?
Tilde operator in C
Data type for holding the count of elements in a data structure
What does #QNANO signify or mean in C?
Linux on reboot process with PPID 1 do not clean up resources (socket)
Why is this implicit conversion (between different pointer types) valid?
Exc_Bad_Access in C
Converting python string object to c char* using ctypes
Why does this struct not align properly?
"invaiid operands to binary *" when assigning to uint* after g_malloc()
Calculator with one function
How to ignore a define directive?
Implicit declaration of function is invalid in C99
Read serial port from micaz
vfprintf() throws SegFault - but input is well-defined?
People Counter Using Pic and c
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.