#How can I check if the character a user inputted is more than 1 character?

13 messages · Page 1 of 1 (latest)

rare locustBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

humble magnet
#

strlen(x)

nimble cosmos
#

ahh ok sick is that in the std library?

humble magnet
#

its in string.h, which comes standard ^^

nimble cosmos
#

Ahh ok that makes sense. So would I initialize the input variable as a character or a string ?

humble magnet
#

as a cstring, yes

#

but

plush sluice
#

btw how are you getting the input?

#

you must always set a limit on the input function itself, that's why gets is deprecated, it got no such feature.

humble magnet
#
char buff[2]; // example: {'a', '\n'}
scanf("%s", buff);

int i = buff[1] == '\0'; 
//if i == 0, string is 1 character, if not, its to long

//safety measures (beause scanf does not nullterminate a buffer if the input is too long):
buff[1] = '\0'
nimble cosmos
#

hold on i ended up ditching this program completley thank you though

#

!close

rare locustBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity