Consider the following declaration:
Code:
char error_msg[15] = "";
I call a function which essentially populates this error message with either an error message (in the case of an error), or with SPACES (if no error is encountered). For reasons I donīt need to get into in this post, I trim the string if it is returned to me as SPACES.
In the relevant section of the code, I check for its length:
Code:
printf("Length of error_msg = %d\n", strlen(error_msg));
When the error message comes back as spaces, the result of trimming the string and executing the line above is always 0. I interpret that to mean that the array is empty, and that the first element of the array is a null character (\0).
But the string compare below always returns a 32:
Code:
compare_result = strcmp(error_msg, "")
So I decided to do a printf to check the first element of the error message array:
Code:
printf("First element of the error msg array: %d", error_msg[0]);
I print the character as an integer in order to see the decimal 0, which corresponds to the null character. But the result I get is the decimal 32, which corresponds to the "blank space" character. Now, if there is a blank character as the first array element, shouldnīt the array length be GREATER than 0?
I think thereīs something Iīm missing here...
Thanks