The program it's entering the if... but it won't change the string content. There are many errors:
After the celsius conversion correct the code with one of the following variants:
Otherwise:
In the first example you have all the strings as constants and desc is just a pointer to a constant string, you can move the pointer using the = operator and change which string is referenced.
In the second desc is an array that can hold 50 chars, the first assignment is optimized by the compiler which does the strcpy for you under the hood, strcpy copies each char until NUL is found, into the memory location provided as the first argument.
- do is a reserved keyword (do...while loop) and even if it compiles you shouldn't name a variable or a function as a keyword.
- I don't know if it was formatted wrongly by a paste but in the format strings there are spaces after the % sign, better remove them.
- You're redeclaring desc many times in a inner scope
- You have to study better how strings are handled in C, in high level languages a simple assignment is enough, in C it may be not.
After the celsius conversion correct the code with one of the following variants:
C:
const char* desc = "if statement is not running :(";
if (renamed_do == -40) {
desc = "Ouch! Cold either way !!";
}
// ...
Otherwise:
C:
char desc [50] = "if statement is not running :(";
if (renamed_do == -40) {
strcpy(desc, "Ouch! Cold either way !!");
}
// ...
In the first example you have all the strings as constants and desc is just a pointer to a constant string, you can move the pointer using the = operator and change which string is referenced.
In the second desc is an array that can hold 50 chars, the first assignment is optimized by the compiler which does the strcpy for you under the hood, strcpy copies each char until NUL is found, into the memory location provided as the first argument.