Questions about user input in guess

I had questions about user input in the function guess

  1. Is the user allowed to enter strings with spaces and/or new line characters? Because when I use scanf to read the user input, it only reads up to space, meaning that the second part of the string (after space) is read in second iteration, giving feedback twice.

  2. How do we deal with inputs longer than k? If I allocate a buffer of a certain size to store user input, and if the input happens to be longer than the buffer size, it would cause buffer overflow and hence undefined behaviour. How do I deal with it?

  1. “The behavior in the case of non-character inputs or too short inputs is undefined.” - Project Description

  2. That is up to you to find out. A word that is not in the dictionary (this includes words of length >k) is an invalid guess. Basically, you need to check if there is another character after the k -th one.

Best,
Tim

1 Like

Note that undefined behavior is wrong, so a solution that causes this is not actually a solution.

Perhaps the manpage for fscanf can offer a solution…

i don’t quite get what exactly is meant by “The behavior in the case of non-character inputs or too short inputs is undefined.” does that mean we ignore these cases or does that mean we should handle these cases and consider it as wrong cases, i don’t get it and i do find the sentence quite vague.

Undefined behavior means that we do not test for these cases and you can do whatever you want.

5 Likes