Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Spell Checking (12 Points). Written Hawaiian also has fairly simple spelling rules for determining if a word is a valid word in the language (even

Spell Checking (12 Points).

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).

I have provided you with a sample data file in ~ee160/Homework/Hw3/moolelo, but you should test your program first with your own data. The makefile in that directory can also be used to compile this program with the command:

 make spchk 

Your executable will be called spchk.

WDS.C

/* Program File: wds.c Other Source Files: chrutil.c Header Files: tfdef.h, chrutil.h This program reads standard input characters and prints each word on a separate line. It also counts the number of lines, words, and characters. All characters are counted including the newline and other control characters, if any. */ #include #include "tfdef.h" #include "chrutil.h" #define INTERACT /* */ main() { signed char ch; int inword, /* flag indicating when in a word */ lns, wds, chrs; /* Counters for lines, words, chars. */ #ifdef INTERACT printf("***Line, Word, Character Count Program*** "); printf("Type characters, EOF to quit "); #endif lns = wds = chrs = 0; /* initialize counters to 0 */ inword = FALSE; /* before beginning we are not in a word */ while ((ch = getchar()) != EOF) /* while there are more characters */ { chrs = chrs + 1; /* count characters */ if (ch == ' ') /* if newline char */ lns = lns + 1; /* count lines */ /* if not in a word and not a delimiter */ /* then this must be the beginning of a word */ if (!inword && !delimitp(ch)) /* if not in word and not delim. */ { inword = TRUE; /* remember we are in a word */ wds = wds + 1; /* count words */ } /* otherwise if in a word, but found a delimiter */ /* then we just went beyond the end of the word */ else if (inword && delimitp(ch)) /* if in word and a delimiter*/ { inword = FALSE; /* we are no longer in a word*/ putchar(' '); /* end word with a newline */ } if (inword) /* if in a word */ putchar(ch); /* print the character */ } /* print the results */ printf("Lines = %d, Words = %d, Characters = %d ", lns, wds, chrs); }

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

int is_h_consonant(char c){ return 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'; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

the OS isn't aware of User level thread Kernel level thread

Answered: 1 week ago