Comments on C Command Line Tutorial 6 - Code indentation, increment/decrement operators, do-while and for loops, and more
We have covered a total of 5 C programming tutorials so far. Each tutorial focused on something specific. In process of remaining close to the topic, some generic concepts remained untouched. Some of those concepts we'll be discussing here in this tutorial.
2 Comment(s)
Comments
You keep repeating your faulty 'getchar' example - where you ignore the first character (unless it is an EOF). If the first line is empty (ie only an EOL), your count will be wrong. Doesn't say much for your c-experience!!
Thanks for your comment. The getchar() example is used here to just explain code indentation, so the focus is not the logic here. Now, coming to the 'faulty' nature of the code, this piece of code was first used here (https://www.howtoforge.com/c-programming-tutorial-part-3-character-variables/), and I specifically mentioned the following limitations in that tutorial:
"Note that our code assumes user will provide at least one line. Couple of corner cases aren't handle intentionally to keep things simple. One is when the user provides EOF without providing any other character in input, and the other is when a line has been provided without providing a newline character."
So I guess I made it amply clear what all cases the code doesn't handle, so it won't be correct to label it as 'faulty'. Let me know if you have any more doubts.