A newbie to C++ here. I need help with counting array length's, I have an array that i only want the user to be able to enter up to ten characters, but lets say if i enter eleven, the array is expanded out to eleven charactes, and i dont want that. i want the array to be cut off at ten.
so far this is the code that i have.
/* Welcome to Dungeon, This will be a simple game */
/* that will require the users name, and confont him */
/* with a maze in which he must navigate! */
/* Good Luck! */
#include <iostream.h>
int main()
{
char UsrName[10];
//will prompt user for name to be used throughout the game
cout<<"Welcome to Dungeon!\nPlease enter your name!\nYour name can only be up to 10 characters long.\n";
//write a function to stop array from becoming over ten characters long
cin>>UsrName;
cout<<"Welcome "<<UsrName<<"!";
}
i need to count the array on character at a time in a loop, after each iteration it will check to see what number of the count that it is on. if it is at ten it will simply cut off the end of the array leaving with a nice neat little array. Any help would be greatly appreciated. As to the fact that i am a newbie to C++ any help on better ways to write my code would be much appreciated.