I have a 5-cell array. I define it this way:
char array[5];
That's how I get from the user:
cin.getline(array, 6);
The problem is that if the user types a string of 6 characters or more, there is a memory leak and the program gets stuck.
Is there a way to limit and make sure that if the user types less than five characters or more than five characters, he will receive an error message?
Thank you
Aucun commentaire:
Enregistrer un commentaire