A user defined function in c++ to read the content from a text file STORY.TXT , count and display the no. of alphabets present in it.

User defined function in  c++ to read the content from a text file STORY.TXT , count and display the no. of alphabets present in it.

#include<iostream.h>

#include<conio.h>

#include<fstream.h>

#include<ctype.h>

#include<stdio.h>



void main()

{              clrscr();

                char str[50];

                fstream file;

   file.open("Story.txt",ios::in|ios::out|ios::trunc);

   cout<<"\nEnter string\n";

   gets(str);

   int i;

   for(i=0;str[i]!='\0';i++)

      file.put(str[i]);

   file.seekg(0,ios::beg);

   int ctr=0;

   for(i=0;str[i]!='\0';i++)

   {           if(isalpha(str[i]))

                                ctr++;

   }

   cout<<"\nNumber of alphabets is\t"<<ctr;

   getch();

}





OUTPUT:



Enter string                                                                   

KARTHIKRAO88.RAO                                                               

                                                                                

Number of alphabets is  13

No comments:

Post a Comment