I'm chewing my way through "C Programming for absolute beginners" book, which is wonderful.
For practice, I type in many of the examples in CodeBlocks and compile, just for exercise, then I fiddle around with them.
Here is something I can't figure out.
I sat the something variable to only 5 elements, just to see if I can write something over 5 (well 4..) and see if it prints. And it does.
Why? I don't get that.
For practice, I type in many of the examples in CodeBlocks and compile, just for exercise, then I fiddle around with them.
Here is something I can't figure out.
Code:
#include <stdio.h>
#include <string.h>
main()
{
char month[] = "Oktober"; //ikki neydugt at seta tal í [] tá man definerar string
char something[5]; //ódefineradur string, pláss fyri 24 ASCII chars + \0 string end
printf("What month is it? %s ofc. \n", month);
printf("Which is your favorite month?\n");
scanf(" %s", &something);
printf("Computing\n\n");
printf("Your favorite month is %s\n", something);
printf("%s\n\n", something); //test if the something var holds more than 5 elements
}
Why? I don't get that.