I am new to C++ and I have a dynamic char array with a max size of 30. I need to extract the name from the array into a string but i have no way of knowing how long the name is.
For example someone named Bob should look like: Bob____________________ (_ is blank space)
but it instead reads like: Bob%#$(%$#)%@#*#@$$#
or something of the sort. I know its doing that because its just random unasigned memory, but how can i cut it off at the end of bob so i can add the blank spaces manually?
In case it is unclear i am reading the letters character by character using a for loop that runs 30 times exactly.
this is my current loop
string n = "";
for(int i=0; i<MAX_NAME_LEN; i++)
{
n += name[i];
}
In this case n should be equal to "Bob___________________"
but it is Bob and a bunch of random crap as stated earlier.