Re: Count total no. of characters,words & sentences in a text file



Umesh wrote:
//Sorry my teachers. I've included file opening check in this program.

#include<stdio.h>
int main(void)
{
long int ch,c,num=0,num1=0,num2=0,num3=0;

Use meaningful names and declare them in the scope where they are used.

FILE *f;
f=fopen("c:/1.txt","r");

Whitespace is free, use it. This will only work on a system where
"c:/1.txt" is a valid filename and where "c:/1.txt" exists...

if (f!=NULL)
{
while((ch=getc(f))!=EOF && (ch=getc(f))!=EOF)

Why are you doing this?

{
if(ch==' ') ++num;
if(ch=='.') ++num1;
if(ch<=256) ++num2;
if(ch=='.' && c!=' ') ++num3; // '.' followed by '.' denotes end of a
sentence.

If you are going to add comments, make sure they make sense and agree
with the code.

--
Ian Collins.
.



Relevant Pages

  • Re: In which scope should variables be declared?
    ... >specific scope I can. ... >int foo ... of this loop to the next, DON'T declare it inside the for loop. ... > In this case, if the declaration maps to any cpu time when compiled, ...
    (comp.lang.c)
  • Re: Local variables - quick question
    ... You can't use a variable which isn't in scope within ... possiblity to declare class argument int i - only signal for me is compiler ... > being alive by the garbage collector. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Local variables - quick question
    ... You can't use a variable which isn't in scope within ... You could declare an instance variable i, ... and after that I would like to use int i - new declaration. ... language is defined to prevent local variables from hiding each other. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Looking for a way to convert dec to bin
    ... I prefer to see at a glance what is going to be used. ... this in dot net and declare all variables with the minimum possible scope. ... int i = 5; ...
    (microsoft.public.vb.general.discussion)
  • Re: Really tough ADO Stored Procedure Question. Please Help!!!
    ... @lScenarioID_CopyFrom int, ... DECLARE @ErrMSG varchar--This is the max msg size ... ROLLBACK TRANSACTION ... SELECT @lRowCountHolder = MIN ...
    (microsoft.public.sqlserver.odbc)