Search This Blog

Translate

c program file handling program to count no of spaces ,lines , special symbols,vowels, numbers,words using cmd command line argument

c program file handling program to count no of spaces ,lines , special symbols,vowels, numbers,words using cmd command line argument.

#include
#include
#include
void main(int argc,char *argv[])
{
  FILE *source;
  char ch;
  int lcnt=1,scnt=0,vcnt=0,sc=0,ncnt=0,acnt=0;

  clrscr();
  if(argc!=2)
  {
   printf("Wrong argument");
   exit(1);
  }
  source=fopen(argv[1],"r");
  if(source==NULL)
  {
   printf("\n Source file not found");
   exit(1);
  }
  while((ch=fgetc(source))!=EOF)
  {  if(ch=='\n')
      lcnt++;
     if(ch==' ')
      scnt++;
     if(ch=='a' ||ch=='e'||ch=='i'||ch=='o'||ch=='u')
      vcnt++;
     if(!(ch>='a'&&ch<='z'||ch>='A'&&ch <='Z'||ch>='0' &&ch<='9'))
      sc++;
     if(ch>='0' &&ch<='9')
      ncnt++;
     if(ch=='A')
      acnt++;

  }
       printf("%d\t lines\n",lcnt);
       printf("%d\t spaces\n",scnt);
       printf("%d\t vowels\n",vcnt);
       printf("%d\t special characters\n",sc);
       printf("%d\t numbers\n",ncnt);
       printf("%d\t A word\n",acnt);
  fclose(source);
 getch();
}

C Program example List

Google+ Badge