very true
matsp: I tried using a string instead of a char within my switch statement, but couldn't get it to work. When I declared it outside the switch statement, and then initialized it within, I got the compiler error: "Incompatible types in assignment." When I tried to declare the string within the statement, I got the compiler error "String undeclared..." (pointing meto the line wheren I'm trying to print it. I tried testing this idea in a program of its own, within an if statement, and got the same results. Here's the two codes I used respectively:
Code:
#include <stdio.h>
int main () {
int n=1;
if(n==1){
char string[]="+";
}
else{
char string[]="";
}
printf("%s", string);
return 0;
}
Code:
#include <stdio.h>
int main () {
int n=1;
char string[5];
if(n==1){
string="+";
}
else{
string="";
}
printf("%s", string);
return 0;
}
I don't understand why this doesn't work, since declaring/initializing other variable types within if/select statements seems fine.
Also I noticed with the original case, where I was declaring a char within the statement (On one of the three conditions), then used sprintf, I wasn't getting the hexagonal question mark at the front of the string, when I used this by itself in int main, but for some reason I do get it when I use it within a function of its own (with a string as an input parameter), and then call the fucntion in main....The function is of type int and returns 0, but it does apply this process to the input string - just wrongly so.