I have created a char string[100]. I know this array will be big enough for its purpose. The problem is that it often too big. When I print this string array I get the text plus a lot of gobbledygook at the end which I assume is the extra memory at end of string array. How would I approach trimming this using just C.
I suppose I could nest a for loop that adds to a new array that has a size determined by a counter(although this would give a warning being that a VAR is determining size of array) but I suppose there is a much simpler way to do this. Any help would be great!
C strings have a terminating null character.
What you're describing sounds like you're not storing a null character at the end of the used portion of your string.
I did not know that I could terminate with a NULL. I knew once I start contemplating using this many for loops that I was either doing something wrong or there was a simpler way. Thank you!