این برای فایل
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
FILE *k;
char c , c0=EOF,target = 'e';
k=fopen("E:\\mah.txt","r");
c=getc(k);
int lines = 0;
int words = 0;
int targets = 0;
int numbers = 0;
int chars = 0 ;
while(c!=EOF)
{
if(c != ' ' && c != '\n')
{
if(lines == 0)
{
lines++;
}
if(words == 0)
{
words++;
}
if(c == target)
{
targets++;
}
if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9' )
{
numbers++;
}
else if(c != ' ' || c != '\n')
{
chars++;
}
c = getc(k);
}
else if(c == '\n')
{
while(c == '\n')
{
c = getc(k);
}
if((c != ' ' && c != EOF))
{
lines++;
words++;
}
else if(c == EOF)
{
lines++;
}
}
else if(c==' ')
{
while(c == ' ')
{
c = getc(k);
}
if((c != '\n' && c != EOF))
{
words++;
}
}
}
cout << "lines = " << lines << endl;
cout << "words = " << words << endl;
cout << "targets = " << targets << endl;
cout << "numbers = " << numbers << endl;
cout << "chars = " << chars << endl;
fclose(k);
return 0;
}