Anothe newbie question, I'm afraid. (Shold be a forum called Total Newbies o something.)
I might be a bit tired at the present time, but this I don't get:
The following code:
Code:
char correctname[7] = "Myname";
int correctlength = strnlen(correctname);
printf("Name: %s\n", correctname);
printf("Length: %d\n", correctlength);
works like I expect it too. It creates a string, then creates an int variable with the string's length as value. Then it prints the string and the value. 100% obvious an basic.
Output:
Name: Myname
Length: 6
However, when I want to add another string:
Code:
char correctname[6] = "Frank";
int correctlength = strnlen(correctname);
char newname[10]; <--------------------------------- another string variable
printf("Name: %s\n", correctname);
printf("Length: %d\n", correctlength);
suddenly, the int variable correctlength becoes zero.
Output:
Name: MyName
Length: 0
Wha-what-what?! By declaring another char variable, the unrelated int variable counting the length of the previous cha variable, is changed?