Sorry I'm sure how to word my question properly.
I'm working on an assignment and I'd like to add a feature to the error checking.
I have a scanf that asks for a word (which is only 5 characters long max).
If the user inputs a string that is 6 characters long like candle
, it will only copy over candl
.
Here is my take on it. Though I'm sure this isn't the most efficient way to do it.
printf("\n\tEnter word: ");
scanf("%s", input);
if (strlen(input) > MAX_LETTERS){
int i = 0;
while (i < MAX_LETTERS){
word[i] = input[i];
i++;
}
printf("the word is %s", word);
}
Basically checks to see if the input is greater than the max amount of letters allowed. And then if it is, it loops and then only copies over the max amount of letters. Any help would be very much appreciated. Thank you in advance!