Hi, all. I'm having some problems with error checking for strings that has more than one word (i.e. sentences or phrases).
Say for example, I need the user to input a book title into an array (e.g. booktitle[40]).
I also need to do some error checking to see if the booktitle input is more than the allowed number of characters inside the array (i.e. booktitle[40]). If it is more than 39 characters, I need to notify the user than they have entered more than the number of characters allowed.
If I used scanf for input, the counting of characters would be straight forward but only the first word can be counted. Therefore, I tried to use gets or fgets, which would be able to store the whole booktitle but I am at a lost in trying to figure out how to do the above error checking.
Is there a way around it?
Thanks and regards,
Darryl HB
Say for example, I need the user to input a book title into an array (e.g. booktitle[40]).
I also need to do some error checking to see if the booktitle input is more than the allowed number of characters inside the array (i.e. booktitle[40]). If it is more than 39 characters, I need to notify the user than they have entered more than the number of characters allowed.
If I used scanf for input, the counting of characters would be straight forward but only the first word can be counted. Therefore, I tried to use gets or fgets, which would be able to store the whole booktitle but I am at a lost in trying to figure out how to do the above error checking.
Is there a way around it?
Thanks and regards,
Darryl HB