write a program that reads a text file specified by the user

write a program that reads a text file, specified by the user, line by line. The program will count blanks, digits, vowels, and consonants. USE FOR LOOPS AND STRINGS. Good program structure, indentation, meaningful variable names and prompts are required. All variables used must be local and your name and comments must be included. The blank count, digit count, vowel count and consonant count should be printed to the screen at the end. In C++... thank you.

Solution

you can compile this program in c/c++ doesn\'t matter. Do try it

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<ctype.h>

read_file(char*);

void main()
{
char ch,*filename=\"file.txt\";
FILE *fpt;
int space,digit,vow,conso;
clrscr();

fpt=fopen(filename,\"a+\");
if(!fpt)
{
printf(\"\ \\\"%s\\\" Not Found . terminating......\",filename);
exit(0);
}
space=digit=conso=vow=0;
while((ch=fgetc(fpt))!=EOF)
{

if(isspace(ch))
space++;

if(isdigit(ch))
digit++;

if(isalpha(ch))
   { switch(tolower(ch))
                {
                                case \'a\' : vow++;
                                                    break;
                                case \'e\' : vow++;
                                                    break;
                                case \'i\' : vow++;
                                                    break;
                                case \'o\' : vow++;
                                                    break;
                                case \'u\' : vow++;
                                                    break;

                       default    : conso++;
                                                    break;
                }
   }
}

fflush(fpt);

fprintf(fpt,\"\ No of vowels :   %d\",vow);
fprintf(fpt,\"\ No of consonants : %d\",conso);
fprintf (fpt,\"\ No of digits : %d\",digit);
fprintf(fpt,\"\ no of white spaces : %d\",space);
fclose(fpt);

printf(\"\ FILENAME : \\\"%s\\\"\",filename);
read_file(filename);

getch();


}

read_file(char *filename)
{
char ch;
FILE *read=fopen(filename,\"r\");

if(!read)
{
printf(\"\ \\\"%s\\\" file can not be read!!---\ \",filename);
getch();
exit(0);
}


printf(\"\ CONTENTS OF \\\"%s\\\"\ \",filename);
while(1)
{
ch=fgetc(read);
if(ch!=EOF)
printf(\"%c\",ch);
else
break;
}
fclose(read);
//getch();
}

write a program that reads a text file, specified by the user, line by line. The program will count blanks, digits, vowels, and consonants. USE FOR LOOPS AND ST
write a program that reads a text file, specified by the user, line by line. The program will count blanks, digits, vowels, and consonants. USE FOR LOOPS AND ST

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site