I am currently working on a program that inputs a line from a file, then reads the vowels in the file, next I am going to count the number of letter a within the program.
Below is the program I have done but it is not working. It opens the file, reads the line, closes the file. Next it opens the file, and read the vowels within the file. Next it is suppose to open the file and count the number of letter a.
The line "Hgj a dsfsIwgEfeEw a weUfewUfewIfOO" is the frist line of .txt n the hello.txt is the file.
My void count_a_fnc() part seems to have some problems.
Thanks
#include <stdio.h>
#include <string.h>
char next;
char *str = "Hgj a dsfsIwgEfeEw a weUfewUfewIfOO";
char *ptr;
FILE *file_ptr;
int count_a=0;
int i;
int a;
int read_vowels;
void read_from_file();
void print_vowels_fnc();
void count_a_fnc();
int main(int argc, char *argv[])
{
read_from_file();
printf("vowels read\n\n");
print_vowels_fnc();
printf("letter a\n\n");
count_a_fnc();
printf("\n\n");
system("PAUSE");
return 0;
}
void read_from_file()
{
file_ptr = fopen("Hello.txt","r");
if( file_ptr !=NULL);
{
while(1)
{
next = fgetc(file_ptr);
if (next != EOF) printf( "%c", next);
else break;
//*ptr= fgetc(file_ptr);
//if(next == 'a' || next == 'e'|| next == 'i' || next == 'o' || next == 'u')
// printf( "%c", next);
}
fclose( file_ptr );
}
}
void print_vowels_fnc()
{
file_ptr = fopen("Hello.txt","r");
if( file_ptr !=NULL);
{
while(1)
{
next = fgetc(file_ptr);
if (next != EOF)
{
if(next == 'a' || next == 'e'|| next == 'i' || next == 'o' || next == 'u')
printf( "%c", next);
if(next == 'A' || next == 'E'|| next == 'I' || next == 'O' || next == 'U')
printf( "%c", next);
}
else break;
//*ptr= fgetc(file_ptr);
//if(next == 'a' || next == 'e'|| next == 'i' || next == 'o' || next == 'u')
// printf( "%c", next);
}
fclose( file_ptr );
}
}
void count_a_fnc()
{file_ptr = fopen("Hello.txt","r");
if( file_ptr !=NULL);
{
while(1)
{
next = fgetc(file_ptr);
if (next != EOF)
ptr=str;
for(i=1;i<=strlen(str);i++){
count_a_fnc();
ptr++;
if (*ptr == a);
count_a++;
system ("PAUSE");
}
}
fclose( file_ptr );
}
}