[Solved] C function skips if statements in do while loop and executes the last if only, but doesn’t in second IDENTICAL function [duplicate]


If the line

if (choice == "foodSize")

is working at all, then you are depending on compiler optimizations. What this is doing is comparing where in memory those two strings are located; if it is true, this is only because the compiler optimized them into two pointers to the same string. The correct way to compare strings is with strcmp:

if(strcmp(choice, "foodSize") == 0)

This will actually compare the contents of the strings.

9

solved C function skips if statements in do while loop and executes the last if only, but doesn’t in second IDENTICAL function [duplicate]