#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
#include(ctype.h)
int main( )
{
char ch;
int line=0, space=0, ct=0;
clrscr( );
printf("Enter the required no. of lines:\n");
while((ch=getchar( ))!=EOF)
{
if(ch==10) { line++; }
if(isspace(ch)) { space++; }
ct++;
}
printf("\nNumber of Lines : %d", line+1);
printf("\nNumber of Words: %d", space+1);
printf("\nTotal Number of Characters: %d", ct);
getch( );
return 0;
}
Explanation:-
Here the 1st condition (ch==10) checking whether the line is ended or not. And ascii value of enter key is 10. (Note:- After completing every line, press enter key. Then only it counts as Line).
The 2nd condition (isspace(ch) checking for spaces between the words. And here, isspace is a special function and it checks whether the character is space or not.
Note:- After completing all the lines, press Ctrl + Z to stop the loop.
Monday, January 26, 2009
Subscribe to:
Post Comments (Atom)
hey...wats dat EOF in the while condition???
ReplyDeleteEOF indicates 'End of the File'. The loop will terminate when the user press Ctrl+Z (^z) in the output screen, which is equal to 'EOF'
ReplyDeletewrite a c-program to find number of lines, words and characters in a given text file using command line arguments
ReplyDeleteplease help me with this program!!!!!!
write a c program to find total no of lines,total no of characters,total no of words using text editor????
ReplyDeleteplease help me with this program....
write a c program about macroprocessor using SIC/XE machine????
ReplyDeleteThanks my dear,your code is free from bugs thanks a lot......
ReplyDeletehow to sort a character array without using strcmp( )??
ReplyDeleteThere is one problem with this program if we press ctrl+z even before typing anything on output screen it shows no of lines=1,no of word=1 and no of charecters=0 when we enter there nothing it has to show us the output zero please correct this error
ReplyDeleteIS there an alternate method
ReplyDeletetq
ReplyDelete