/*
============================================================================
Name : C-Programming
Author : Code2care
Version : 1.0
Copyright : Code2care.org
Description : 108 : Program to number of lines, words and characters in an inputted String.
============================================================================
*/
#include
#define ENTER 1 /* typing a word */
#define EXIT 0 /* word typing done */
int main(void) {
int ch, newLine = 0, wordCount = 0, charCount = 0;
int currState = EXIT;
while ((ch = getchar()) != '~') {
++charCount;
if (ch == '\n')
++newLine;
if (ch == ' ' || ch == '\n' || ch == '\t')
currState = EXIT;
else if (currState == EXIT) {
currState = ENTER
;
++wordCount;
}
}
printf("\n\nStats : \nNew Lines : %d \nWords : %d \nCharacters : %d\n", newLine,
wordCount, charCount);
return 0;
}
The best way to learn C programming is to practice more and more of programs .
Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.
BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.