Howdy. I'm having a little difficulty with strings, so hopefully somebody here can steer me in the right direction
Anyways, lets say I create a string:
Now, lets say I need to store user input in this string, and go about it by using getchar(), and placing each character individually in the array. Now, I know that in order to be able to use this array as a string, it needs to contain '\0' at the end of the string. However, what exactly is the end of the string?Code:char str[500];
For example, if 150 characters end up getting placed in the array. Is the end of the string considered to be right after the 150th character, or is the end of the string at location str[499]?
If the former is true, I suppose it would be easy enough to place the null character right after you finish reading input. But if the latter is true, I figure it would be easiest to just initialize the entire array as null right off the bat. If so, how could you do that?
Can you initialize it when you create it by going:
Since you only provide one character, would it set the rest of the array to the same character? If not, would you have to create a seperate function to loop through each element and set it to null?Code:char str[500] = {'\0'};
I'm not sure if I'm complicating this too much or not, but it's confusing me substantially. Thanks for any help!