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

Written Hawaiian also has fairly simple spelling rules for determining if a word

ID: 3602736 • Letter: W

Question

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.

You should think about your algorithm before beginning to code this function, and you might want to look at the program

The general algorithm for your program will be similar to the word counting program, but the details will vary. Implement your algorithm in the file spchk.c and use the functions in letters.c to test for the appropriate letters.

(Hint: You might want to write another function similar to delimitp() used in wds.c, but your code will be different from the delimitp() in the text. You can put any additional functions and/or macros you use in your letters.c and letters.h files).

****** This is the original problem with sample code provided by instructor, below is the code I am trying to construct. All the guidlines seem to be applied but when exacuted the output is incorrect. The program compiles fine but I am not getting the answers I need.

Spell A hui hou kakou test kakou

#include <stdio.h>

#include <ctype.h>

#include "letters.h"

int main(){

char ch;

char word[100];

int letterCount = 0;

//INITIALIZE WORDS TO NULL TERMINATOR

for(int i=0;i<100;i++){

word[i] = '';

}

while ((ch = getchar()) != EOF){

printf("IN WHILE LOOP ");//

if(ch != '.' && ch != ',' && ch!= '!' && ch != ' ' && ch != ';' && ch!='?'){

word[letterCount] = ch;

letterCount++;

printf("READ NON-PUNCTUATION as %c ",ch);//

} else{

printf("verifying word... letter count is %d, word is %s ",letterCount, word);//

verify_word(word, letterCount);

for(int i=0;i<letterCount;i++){

word[i] = '';

}

letterCount = 0;

}

}

if(letterCount > 0){

if(word[letterCount-1] == ' ' || word[letterCount-1] == ' ' || word[letterCount-1] == ' ' || word[letterCount-1] == '.' || word[letterCount-1] == '?'){

letterCount--;

}

verify_word(word, letterCount);

}

return 1;

}

// File : letters.h

// By : Keith Shipley

// Login : keithps

// Team : one team

// Date : 25 oct

//contains header bits for driver one

//#define FLUSH while(getchar()!= ' ')

void verify_word(char *word, int len);

//takes char and letter count

//determines if follows hawaiin rules

//retuns yes no

int is_vowel(char);

//inputs char

//determins if a vowel

//returns true false

int is_cons(char);

//inputs char

//determins if a constant

//returns true false

#include <stdio.h>

#include <ctype.h>

#include "letters.h"

int is_vowel(char c){

switch(c){

case 'a':

return 1;

break;

case 'e':

return 1;

break;

case 'i':

return 1;

break;

case 'o':

return 1;

break;

case 'u':

return 1;

break;

case 'A':

return 1;

break;

case 'E':

return 1;

break;

case 'I':

return 1;

break;

case 'O':

return 1;

break;

case 'U':

return 1;

break;

case ''':

return 1;

break;

default:

return 0;

break;

}

}

int is_cons(char c){

switch(c){

case 'h':

return 1;

break;

case 'H':

return 1;

break;

case 'l':

return 1;

break;

case 'L':

return 1;

break;

case 'k':

return 1;

break;

case 'K':

return 1;

break;

case 'w':

return 1;

break;

case 'W':

return 1;

break;

case 'm':

return 1;

break;

case 'M':

return 1;

break;

case 'n':

return 1;

break;

case 'N':

return 1;

break;

case 'p':

return 1;

break;

case 'P':

return 1;

break;

default:

return 0;

break;

}

}

void verify_word(char *word, int len){

//end in vowel

if(is_vowel(word[len-1])== 0){

printf("%s NOT VALID ",word);

return;

}

//all words contain only vowels and hawaiian consonants

for(int i=0; i<len;i++){

if(is_vowel(word[i])==0 && is_cons(word[i])==0){

printf("%s NOT VALID ",word);

return;

}

}

//never two consonants in a row

for(int i=0; i<len-1;i++){

if(is_cons(word[i])==1 && is_cons(word[i+1])==1){

printf("%s NOT VALID ",word);

return;

}

}

//printf("%s IS VALID ", word);

return;

}

Explanation / Answer

#include<stdio.h>
#include <conio.h>
#include <ctype.h>
bool ishawaiian(char,int *);
int main()
{bool legal=true;
char ch;
intlast_ch=0,i;            
char inword[20];
int kt=0,voc,done;
while((ch = getchar()) != EOF)
{inword[kt++]=ch;
if(ishawaiian(ch,&voc))
      {if(voc==1)
         if(kt!=1)
            if(last_ch==1)
                legal=false;
       last_ch=voc;
       }
else
     {if(voc=3&&!(isspace(ch)||ispunct(ch)))
          {legal=false;
           done=0;
           
           while(done==0)
             {ch = getchar();
              if(!(isspace(ch)||ispunct(ch)))
                 inword[kt++]=ch;
                  
             else
                 {done=1;
                 kt++;
                 }
             }  
           }
      kt--;
      printf(" ");
      for(i=0;i<kt;i++)
        printf("%c",inword[i]);
      if(legal)
         printf(": it isvalid ");
      else
         printf(": it isinvalid ");
      legal=true;
      kt=0;
     
      }
}
getch();
return 0;
}    

bool ishawaiian(charch,int* voc)
{charletter[13]={'a','e','i','o','u','h','k','l','m','n','p','w','''};
int i;
for(i=0;i<13;i++)
     {if(ch==letter[i])
         {if(i<5)
             *voc=0;
          else
             *voc=1;
           returntrue;
          }        
      }
*voc=3;

return false;
}