P.cpp:defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
int N_char (FILE *fp)
{int num = 0;
Char s[20];
while (!feof (FP))
{fscanf (FP, "%s", s);//read string num + = strlen (s);//number of characters superimposed
}
printf ("Number of characters (excluding spaces and carriage returns) has%d \ n", num);
Rewind (FP); Wrap back file pointer
return num;
}
int N_world (FILE *fp)
{
Char s[20];
int n = 0, num = 0;
while (!feof (FP))
{
if (fscanf (FP, "%s", s) &&! ( S[0] >= ' 0 ' && s[0] <= ' 9 '))
n++;
Else
num++;
}
printf ("Number of words%d, number%d \ n", n,num);
Rewind (FP);
return n;
}
int N_row (FILE *fp)
{
int n = 1;
Char ch;
while (!feof (FP))
{
if (ch = fgetc (fp) = = ' \ n ')) n++;
}
printf ("There are%d rows \ n", n.); Rewind (FP);
return n;
}
void Main ()
{
FILE *FP;
fp = fopen ("D:\\aaa.txt", "R"); Open File
N_char (FP);
N_world (FP);
N_row (FP);
Fclose (FP);
}
Run Tests
Statistical text Document