Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function that count the number of vowels, the number of consonants and t

ID: 3874714 • Letter: W

Question

Write a function that count the number of vowels, the number of consonants and the average number of letters in each word. The function accept a C-String (char array) or a string object as an argument and return the number of vowels, number of consonants and the average number of letters in each word. Problem: Requirements Use pointers as part of the solution. Read a string from a text file. Write in a text file the string, the number of vowels, the number of consonants and the average number of letters in each word. .

Explanation / Answer

In the below answer pointer is used. It is reading strings from a file ,and avarage number of letters in a word,added with vowel count,consonent count.Follow the C program thoroughly :

#include <stdio.h>

#include <conio.h>

int main()

{

FILE *fp1,*fp2;

char fname1[50],fname2[50];

char ch;

int vowel=0,consonant=0,wordcount=0,lettercount=0, avglcount=0;

// Prompt to enter filenames

printf ("Enter a filename : ");

gets(fname1);

printf ("Enter a filename : ");

gets(fname2);

  

// Open file in read-only mode

fp1 = fopen(fname1,"r");

// Open file in write mode

fp2 = fopen(fname2,"w");

if (fp1 == NULL)

{

printf("Cannot open %s for reading ", fname1);

exit(1);

}

else

{

//Repeat until End Of File character is reached.

while ((ch=getc(fp1)) != EOF)

{

// Increment letter count

if (ch != ' ' && ch != ' ')

{

++lettercount;

}

// Increment word count

if (ch == ' ' || ch == ' ')

{

++wordcount;

}

//avarage lettercount per word

{

avglcount = lettercount/wordcount ;

}

//Increment vowel count

else if((ch=='a')||(ch=='A')||(ch=='e')||(ch=='E')||(ch=='i')||(ch=='I')||(ch=='o') ||(ch=='O')||(ch=='u')||(ch=='U'))

{

vowel++;

}

// Increment consonant count

else if {

consonant++;

}

//string is being copied to the other file

else

{

fputc (ch, fp2);

printf ("string is copied");

}

/* If file is opened successfully, then write to file */

fprintf(fp2, "%d, %d %d ", avglcount,vowel,consonant);

/* close the files */

fclose(fp1);

fclose(fp2);

getchar();

return(0);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote