SLIDE1

Thursday, January 8, 2015

chương trình c đếm số từ trong file

//chương trình đếm số từ trong file
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *t;
int k=0,dem=0;
t=fopen("E:\\toan.txt","r");
if(t==NULL)
{
printf("error");
exit(0);
}
char c;
do
{
c=getc(t);
if((c>='a' && c<='z' )||(c>='A' && c<='Z'))k=1;
if((c==' ' || c=='\t' || c==10 || c==EOF)&&k==1 )
{
dem++;
k=0;
}
}while(c!=EOF);
printf("so tu = %d\n",dem);
}