统计文件中字符

| January 3, 2008 18:50 | timmy | Via Original

#include <stdio.h>
#include <stdlib.h>
void main()
{
  FILE *fp;
  char ch;
  int letter,digit,other;
  letter=digit=other=0;
  if((fp=fopen("a.txt","r"))==NULL){
    printf("File open error!\n");
    exit(0);
  }
  while(!feof(fp)){
    ch=fgetc(fp);
    if(ch>='A'&&ch<='Z'||ch>='a'&&ch<='z')
      letter++;
    else if(ch>='0'&&ch<='9')
      digit++;
    else
      other++;
  }
  printf("letter=%d,digit=%d,other=%d\n",letter,digit,other);
}

Tags:
Program/Code » C/C++ | Comments(0) | Trackbacks(0) | Reads(184)
Add a comment
 Site URI
 Email
  Password Optional
 Nickname  *  [Register]
               

 
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Remember