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: 3731813 • 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.

I HAVE LETTERS.C AND LETTERS.H COMPLETED. I ALSO HAVE A LOT OF SPCHK.C COMPLETED BUT AM HAVING TROUBLE GETTING IT TO READ EACH INDIVIDUAL LETTER AND THUS PRINT OUT IF THE COMPLETE WORD IS VALID DETERMINED BY THE 3 PARAMETERS STATED IN THE QUESTION ABOVE. i'M JUST LOOKING FOR HELP ON FIXING THE SPCHK.C TO PRINT CORRECTLY. WE HAVE NOT LEARNED ARRAYS YET SO THEY CANNOT BE IN THE FILE.

Proper sample output:
aloha mahalo alloha mahalot
aloha It is valid!
mahalo It is valid!
alloha It is not valid!
mahalot It is not valid!

letters.c

#include "letters.h"

int is_vowel(char c)
{
   if ( c == 'A' || c == 'E' || c == 'I' || c == 'O' ||
c == 'U' || c == 'a' || c == 'e' || c == 'i' ||
c == 'o' || c == 'u')
{
return 1;
}
  else{

return 0;
}
}
int is_h_consonant(char c)

{   
if ( c == 'H' || c == 'h' || c == 'K' || c == 'k' ||
c == 'L' || c == 'l' || c == 'M' || c == 'm' ||
c == 'N' || c == 'n' || c == 'P' || c == 'p' ||
c == 'W' || c == 'w' || c == '`')
{
return 1;
}
else{

return 0;
}
}

/* This function return True if there is either whitespace or punctuators */

int whitespace(char c)
{
if(c == ' ' || c == ' ' || c == ' ')
return 1;
else
return 0;
}

int punctuation(char c)
{
if (c == '.' || c == ',' || c == ';' || c == '?' || c == '!')
return 1;
else
return 0;
}


int delimp(char c)
{
if(whitespace(c) || punctuation(c))
return 1;
else
return 0;
}

letters.h

#define TRUE 1
#define FALSE 0

int is_vowel(char);
int is_h_consonant(char);
int delimp(char);

spchk.c


#include <stdio.h>

#include "letters.h"

int main()

{

       char ch;

       char last_ch;

       int inword;

       int hi;

       inword = FALSE;

       hi = FALSE;

       last_ch = 'a';

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

       {

               if( !inword && !delimp(ch))

               {

                       inword = 1;

               }

               if(inword)

               {

                       if(is_vowel(ch))

                       { hi = TRUE;

                       }

                       else if(is_h_consonant(ch))

                       {

                               if((is_h_consonant(ch) &&

                                       !is_h_consonant(last_ch))

                                       || (!is_h_consonant(ch) &&

                                       is_h_consonant(last_ch)))

                               { hi = TRUE;

                               }

                       }

                       else if(is_h_consonant(last_ch))

                               hi = FALSE;

                       else if(delimp(ch) && is_vowel(last_ch))

                       { hi = TRUE;

                       }

                       else

                       { hi = FALSE ;

                       }

               }

               if(inword && delimp(ch))

               {

                       inword = 0;

                       if(hi)

                               printf(" it is valid! ");

                       else

                               printf(" It is invalid! ");

                  last_ch = ch;

                 hi = FALSE;

       }

}

Explanation / Answer

spchk.c

Here I am suggesting only the minor changes that will be required to check the 3 condition in spchk.c as most of your program is correct.

if your program is generating wrong output , these changes will correct it.

int first=0; /*this parameter will ensure that the first character of word is vowel*/

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

{

if( !inword && !delimp(ch))

{

inword = 1;

}

if(inword)

{

if(is_vowel(ch))

{ hi = TRUE;

first=1;
  

}

else if( first==1) /*checks if first character is vowel*/

{

if((is_h_consonant(ch) &&

is_vowel(last_ch))

|| (is_h_vowel(ch) &&

is_h_consonant(last_ch))) /*this "if" will check the alternating vowel and consonants */

{ hi = TRUE;

}

}

else if(is_h_consonant(last_ch))

hi = FALSE;

else if(delimp(ch) && is_vowel(last_ch))

{ hi = TRUE;

}

else

{ hi = FALSE ;

}

}

if(inword && delimp(ch) && is_vowel(last_ch)) /* here "is_vowel(last_ch)" will check whether the previous character before the delimeter is vowel*/

{

inword = 0;

if(hi)

printf(" it is valid! ");

else

printf(" It is invalid! ");

last_ch = ch;

hi = FALSE;
first=0;

}

}