I have to do a C++ project where I create an array that can take a maximum of 140 characters from the user. However, I also have a menu of multiple things I am able to do with the matrix. In that menu, if the user has yet to enter any text into the array, the user is to get an error message notifying them that they must enter text using option 1 first. I will put the code I have so far below, but I am not sure how to go about setting up a way to determine if any information has been entered for the array yet? I am thinking it has something to do with pre-defining the values in the array and seeing if they are still those values, but arrays are new to me and I'm at a loss on where to start here.
2. The terminating null. What you will have in your character array is a proper C-string. The string functions in C library operate on null-terminated C-strings.
You will thus need to do two things:
1. Make sure that the array is initialized to look like an empty C-string.
2. Test for empty C-string.
PS. Plain arrays and global variables are both rather challenging things to play with.
Ok, took what you guys said into consideration. The program wouldn't let me input it exactly how you suggested, but here is the closest I got:
char text[140]="0";
since it is char, it wanted the quotes. Hopefully this is still defining it as an empty set.
if ((options=="2" || options=="3" || options=="4") && text != NULL)
The bold above was the only thing it would seem to accept there. When I tried using your suggestion, it was giving me some type of error message. Alternatively, it also allowed me to use "text != "0" and both seem to be doing the same thing. So far, it seems to be doing what I want, so thanks.
Be more specific. The compiler tries to tell you something very important. Learn to use that feedback.
This is not what you think: char text[140] = "0";
It is equivalent to:
1 2 3
char text[140];
text[0] = '0';
text[1] = '\0';
The first character in the array becomes what looks zero when printed.
The second character in the array becomes null.
Therefore, the array does not have empty string "". It has "0".
The array is global.
If you want to initialize it in the declaration to empty string, then use char text[140] = "";
The other way is to assign null to the first array element in the main() function.