69.4k views
5 votes
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 wds.c from lecture (and on wiliki in ~ee160/Code.lect/Chars/wds.c) for guidance. (That file is similar, but better, than the code in Chapter 4). 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).

User AdamZ
by
5.1k points

1 Answer

3 votes

Answer:

see explaination

Step-by-step explanation:

#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;

}

User Miltonb
by
4.8k points