Consider the following declaration:
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.
char error_msg = "";
In the relevant section of the code, I check for its length:
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).
printf("Length of error_msg = %d\n", strlen(error_msg));
But the string compare below always returns a 32:
So I decided to do a printf to check the first element of the error message array:
compare_result = strcmp(error_msg, "")
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?
printf("First element of the error msg array: %d", error_msg);
I think thereīs something Iīm missing here...