Can you write a c program to count the number of words with not more than 5 consonants in a text file?

Word

1 answer

Answer

1258160

2026-03-19 15:26

+ Follow

FILE *fPtr = fopen("ConsonantInput.txt", "r");

char sWord[1024];

int nWordCount = 0;

while(!feof(fPtr))

{

memset(sWord, 0x00, sizeof(sWord));

fscanf(fPtr, "%s", sWord);

short nCount = strlen(sWord);

short nConsonantCount = 0;

for(int i = 0; i < nCount; ++i)

{

switch(sWord[1])

{

case 'A':

case 'E':

case 'I':

case 'O':

case 'U':

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

case '-':

{

break;

}

default:

++nConsonantCount;

}

if(nConsonantCount >= MAX_CONSONANT_NUMBER)

{

++nWordCount;

break;

}

}

}

printf("Number of Words : %d, Time Taken : %.2f", nWordCount);

fclose(fPtr);

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.