Afjörmun
Last updated
Last updated
I believe the tricky part for this question is to deal with the input in C. The main algorithm is not that hard. It is just you upper the first letter and iterate all the way till the end, if it isupper()
, then turn it to lower letter. Otherwise, just leave it as it is.
MAX_LEN
should be the actual length of the string +1 because fgets()
may read the \n
character!
Note that sometimes this method is not 100% safe. So, the safest way I recommend is to use cs1010 library.
Suppose we input an integer with \n
, to read it into a variable using scanf()
, use the code below:
This will be a bit tricky. For the first integer, we can still use the method above Read an integer with newline. But for the remaining integers, we should use the following method to read:
The leading \n
is used to consume the \n
that is left in the stdin
.
To read a line in C, it is "safer" to use fgets()
. See more about it in .