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

Write a prgram in C language. Written Hawaiian also has fairly simple spelling r

ID: 644799 • Letter: W

Question

Write a prgram in C language. Written Hawaiian also has fairly simple spelling rules for determining if a word is a valid word in the language (even if the meaning is unknown). They are:

All words contain only vowels and Hawaiian consonants.

All words end in a vowel.

Within a word, two consonants NEVER appear adjacent.

Write a program which reads lines of Hawaiian text from a file (using redirection, so you will not need to prompt), and lists each word found on a separate line indicating whether it is a valid Hawaiian spelling or it is invalid. Any non-letter characters (e.g. white space or punctuation characters) in the file should be treated as delimiters, but otherwise ignored and not appear in the output.

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

int isValid(char word[256]){
   int i = 0, flag = 0;
   while(word[i] != ''){
       char ch = tolower(word[i]);
       if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'){
           flag = 0;
       }
       else{
           if(ch == ',' || ch == '.'){
               flag = 0;
           }
           if(flag == 1){
               return 0;
           }
           else if(ch >= 'a' && ch <= 'z'){
               flag = 1;
           }
       }
       ++i;
   }
   return 1;
}

int main(){
   FILE *fp = fopen("Hawaiian.txt", "r");
   char word[256];
   while(fscanf(fp, "%s", word) != EOF){
       if(isValid(word)){
           printf("%s is an Hawaiian word ", word);
       }
       else{
           printf("%s is not an Hawaiian word ", word);
       }
   }
   fclose(fp);
   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