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); }
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"); }
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
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