Hey, i've just started studying programming, and trying to put together a list of all the different types of arrays and how to use them into a usable program. I ended up with this, but it comes up with chapter6.exe not working when i try to "run" the program, using Codeblocks 13.12
put them into a usable program** oops
>>51788352
What's Hero1 supposed to contain? Are you writing the address of a static character string into an 8-bit integer?
>>51788409
Hero1 is supposed to contain "Batman", have I done something wrong?
>>51788447char Hero1 = "Batman";
This line defines a single-character (probably 8-bit) variable named Hero1, and a static piece of string data containing "Batman\0", handled as a pointer to where the static data ended up when the program was built.
Old C's lax typing rules may let you assign the (32/64 bit) data pointer into the 8-bit variable but nothing useful is likely to happen. When the Hero1 variable is passed into printf (I think it gets promoted into an "int" because of varargs) its value is interpreted by %s as a pointer but the 8-bit char is too small to contain any meaningful address, potentially making the printf statement read something it shouldn't.
>>51788447
hero1 is declared as a single char not a char array, it can hold one letter
>>51788569
Wow you're right haha, I assigned [10] to it and it runs perfectly, thank you. I must admit I don't understand much of what you're saying, but thank you for pointing out the problem. I will try to get my head around this :P
>>51788614
You should probably read a bit about how C's strings and arrays are basically just a thin convenience layer on top of raw memory pointers.
Also, if you didn't already, turn on all compiler warnings. If your Code::Blocks setup is using GCC, the relevant compiler argument is -Wall . You may find a checkbox for it somewhere in the project or compiler settings. Most compilers can produce warnings about many silly type errors like this.
>>51788673
Where would I find these compiler warnings? and I am using GCC
>>51788673
oh nevermind I got it I think, thanks that's really helpful!