Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include<stdio.h>
#include<conio.h>
#include<string.h>
//#define nl 0
void main()
{
	int No_Lines=0,No_Words=0,No_Letters=0,No_Sentence=0;
	int Letter;
	while((Letter=getchar())!=EOF)
	{
		if(Letter==' ')
			++No_Words;
		else if(Letter=='\n')
			++No_Lines;
		else if(Letter=='.')
			++No_Sentence;

	}
	printf("Words\tLines\tSentence\n");
	printf("%d\t%d\t%d",No_Words,No_Lines,No_Sentence);
	getch();
}


[edit]Code Block added - OriginalGriff[/edit]
[edit2 + 3]Get rid of damn close tags! Grrrr! - OriginalGriff[/edit 2 + 3]
Posted
Updated 1-Jun-11 1:23am
v3
Comments
karan joshua 1-Jun-11 7:16am    
where you opened the file?
Nithin Sundar 1-Jun-11 7:27am    
Wait a sec.....EOF is used to check for end of file. You are checking EOF for a....integer variable?
OriginalGriff 1-Jun-11 7:31am    
Check the definition: EOF is #defined as -1
It's not good practice, but it will work.
Nithin Sundar 1-Jun-11 7:32am    
Ah alright Thanks! The way he's using it is very misleading. :O
Timberbird 1-Jun-11 7:30am    
Why do you use EOF in the first place?

Try typing a CTRL+Z: if that doesn't work, try CTRL+C, but that may just kill your app.
 
Share this answer
 
Comments
Nithin Sundar 1-Jun-11 7:28am    
The question edit notes you added were hilarious.
OriginalGriff 1-Jun-11 7:33am    
Blasted things! Now that pre tags allow gt and lt symbols to work without being taken and consumed as tags, the "let's not have badly formed HTML to mess up the page" checking adds close tags for stdio.h and so forth - which not appear in the preview, but do in the post. Grrrrr!
Nithin Sundar 1-Jun-11 7:35am    
Yeah. I've had to edit some questions about 4 to 5 times just to make sure they are removed properly sometimes! -_-!
This application does nothing... getchar() is meant to grab input from stdin, which is the user input by default, yet you don't ask the user for input (I guess you can write it on the screen it in if you knew to do it). Additionally, you try to read the user input until EOF, that doesn't make sense, since stdin not a file, so you'll end up stuck in that infinite loop.

See this example:
http://www.cplusplus.com/reference/clibrary/cstdio/getchar/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900