I can't get this simple example to work >_<
It prints dog -_-. I'm hopelessCode:#include <stdio.h>
main(){
char blah[]="dog";
int foo=3;
if (foo==3){
char blah[]="cat";
}
printf("%s",blah);
}
Printable View
I can't get this simple example to work >_<
It prints dog -_-. I'm hopelessCode:#include <stdio.h>
main(){
char blah[]="dog";
int foo=3;
if (foo==3){
char blah[]="cat";
}
printf("%s",blah);
}
This creates a new blah variable local to this small block of code and which hides the original within said block of code and which disappears (is destroyed) once the bracket '}' is reached. The original is untouched. To do what you want you need to use the strcpy function. You need to be sure when you do this that the destination has enough space to store what you need to... which in this case is true.Code:if (foo==3){
char blah[]="cat";
}
Code:if (foo==3){
strcpy(blah,"cat");
}
XD thank you very much it works now!
You need int main and the return statment as well in you code. To make your code more perfect.
ssharish2005