#include <stdio.h>
int fill(char a[], char fn[]);
void Print(char a[], int n);
int countVowels(char a[], int n);
int main()
{
char a[10000];
int n, v;
char fn[30];
printf("name of file:");
scanf("%s", &fn);
n = fill(a, fn);
Print(a,n);
v = countVowels(a, n);
printf("The number of vowels in the file is %d", v);
return 0;
}
int countVowels(char a[], int n)
{
int i, count;
count = 0;
for(i = 0; i < n; i++)
{
if(a[i] == 'a' || a[i] == 'e'|| a[i] == 'i' || a[i] == 'o' || a[i] == 'u' || a[i] == 'A' || a[i] == 'E' || a[i] == 'I'|| a[i] == 'O' || a[i] == 'U')
count = count + 1;
}
return count;
}
void Print(char a[], int n)
{
int i;
for(i = 0; i < n; i++)
printf("%c", a[i]);
printf("\n");
}
int fill(char a[], char fn[])
{
FILE *stream;
int n;
n = 0;
fscanf(stream, "%c", &a[n]);
while(!feof(stream))//while not end of file stream, do this:
{
n++;
fscanf(stream, "%c", &a[n]);
}
fclose(stream);
return n;
}
This post has been edited by afunkhou: 30 October 2009 - 10:21 PM

New Topic/Question
Reply




MultiQuote





|