Help With spell checking

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Help With spell checking
# 1  
Old 03-24-2011
Java Help With spell checking

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
What the program is suppose to do is input a word and when the user press enter the result should read the word and have follow conditions bellow if true
  • All words contain only vowels and Hawaiian consonants.
  • All words end in a vowel.
  • Within a word, two consonants NEVER appear adjacent.


2. Relevant commands, code, scripts, algorithms:
here are the relevant code to spchk.c

Code:
letters.h
#include <stdio.h>
int is_vowel(char c);
int is_h_consonant(char c);
#define TRUE  1
#define FALSE 0
#define FLUSH while(getchar()!='\n')
int convert_up_low(char c);

included w/ letters.c
included #include <stdio.h>
#include "letters.h"
int is_vowel(char c)
{
         /* this function is given a letter and return its value. */

        /*if the letter inputs are true */
      /*if (c=='A' ||c=='a'|| c=='E'||c=='e'|| c=='I'
            ||c=='i'|| c=='O'||c=='o'|| c=='U'||c=='u')
                { c= convert_up_low (char c);
                }*/


        /* if the letter is a vowel (lower or Upper case)*/

        if (c=='A' ||c=='a'|| c=='E'||c=='e'||
            c=='I'||c=='i'|| c=='O'||c=='o'||
            c=='U'||c=='u')
        {
         /* return the vowel upper or lower case*/
        return TRUE;
        }
        else
        {
        /* return false */
        return FALSE;
        }
}
int is_h_consonant(char c)
{
        /* if the letter is a consonant (lower or Upper case)*/
        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 the consonant upper or lower case*/
        return TRUE;
        }

        else
        {
        /* return False */
        return FALSE;
        }
}

also chrutil.h
#define   ERROR     -2

#define   IS_DIGIT(c)   ((c) >= '0' && (c) <= '9')
#define   IS_LOWER(c)   ((c) >= 'a' && (c) <= 'z')
#define   IS_UPPER(c)   ((c) >= 'A' && (c) <= 'Z')
#define   IS_WHITE_SPACE(c)   ((c) == ' ' || (c) == '\t' || (c) == '\n')
#define   IS_PRINT(c)   ((c) >= 32 && (c) < 127)

#define  LOWER     0
#define  UPPER     1
#define  DIGIT     2
#define  PUNCT     3
#define  SPACE     4
#define  CONTROL   5
#define  SPECIAL   6


int dig_to_int(char ch);
char int_to_dig(int n);
char uppercase(char ch);
int getint();

int delimitp(char c);
int whitep(char c);
int punctp(char c);
int vowelp(char c);
int letterp(char c);
int illegal(char c);      /* Tests if c is legal. */

that includes chrutil.c

#include <stdio.h> 
#include "tfdef.h"
#include "chrutil.h"

/*   Function converts ch to an integer if it is a digit. Otherwise, it
 *        prints an error message.
 *        */
int dig_to_int(char ch)
{
     if (IS_DIGIT(ch))
          return ch - '0';
     printf("ERROR:dig_to_int:  %c is not a digit\n", ch);
     return ERROR;
}

/*   Function converts a positive integer less than 10 to a corresponding
 *        digit character.
 *        */
char int_to_dig(int n)
   {
     if (n >= 0 && n < 10)
          return n + '0';
     printf("ERROR:int_to_dig:  %d is not in the range 0 to 9\n", n);
    return  NULL;
   }


/*  Function reads the next integer from the input  */
int getint()
{    int n = 0;
     int got_dig = FALSE;
     signed char ch;


     ch = getchar();                     /* read next char                  */
     while (IS_WHITE_SPACE(ch))          /* skip white space                */
              ch = getchar();
     while (IS_DIGIT(ch)) {              /* repeat as long as ch is a digit */
          n = n * 10 + dig_to_int(ch);   /* accumulate value in n           */
          got_dig = TRUE;
#ifdef DEBUG
printf("debug:getint: ch = %c\n", ch);   /* debug statement */
printf("debug:getint: n = %d\n", n);     /* debug statement */
#endif
          ch = getchar();                /* read next char                  */
     }
     if(ch == EOF) return EOF;           /* test for end of file            */
     if(!got_dig)  return ERROR;         /* test for no digits read         */
     return n;                           /* otherwise return the result     */

}

/* Function tests if c is an alphabetic letter. */
int letterp(char c)
{
     if (IS_LOWER(c) || IS_UPPER(c))
          return TRUE;
     return FALSE;
}


/*   Function returns TRUE if c is a delimiter, i.e., it is a white space
 *        or a punctuation. Otherwise, it returns FALSE.
 *        */
int delimitp(char c)
{
     if (whitep(c) || punctp(c))
          return TRUE;
     return FALSE;
}

/* Function returns TRUE if c is white space; returns FALSE otherwise. */
int whitep(char c)
{
     if (c == '\n' || c == '\t' || c == ' ')
          return TRUE;
     return FALSE;
}

/* Function returns TRUE if c is a punctuation; returns FALSE otherwise. */
int punctp(char c)
{
     if (c == '.' || c == ',' || c == ';' || c == ':'
               || c == '?' || c == '!')
          return TRUE;
     return FALSE;
}


/*   Function checks if c is a vowel. */
int vowelp(char c)
{
     switch(c) {
          case 'a':
          case 'A':
          case 'e':
          case 'E':
          case 'i':
          case 'I':
          case 'o':
          case 'O':
          case 'u':
          case 'U':  return TRUE;
          default:   return FALSE;
     }
}


/* Function tests if c is printable. */
int illegal(char c)
{
   if (IS_PRINT(c) || IS_WHITE_SPACE(c))
     return FALSE;
   return TRUE;
}

3. The attempts at a solution (include all code and scripts):
here's the attempt though i don't know what to do add on 
spchk.c

 /* File Name: spchk.c
 * By: Matthew Yee
 * Login: mgy
 * Date:03/18/2011
 */
#include "chrutil.h"

#include "letters.h"
main()
{    signed char c;
     int inword,         /* flag indicating when in a word    */
     lns, wds, chrs;     /* Counters for lines, words, chars. */

    /* #ifdef INTERACT
     printf("***Line, Word, Character Count Program***\n\n");
     printf("Type characters, EOF to quit\n");
     #endif*/
     lns = wds = chrs = 0;    /* initialize counters to 0               */
     inword = FALSE;          /* before beginning we are not in a word  */

   while ((c = getchar()) != EOF)     /* while there are more characters */
     {    chrs = chrs + 1;               /* count characters     */
          if (c == '\n')                /* 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(c))     /* 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(c))    /* if in word and a delimiter*/
          {    inword = FALSE;                /* we are no longer in a word*/


              getchar();



              putchar('\n');                 /* end word with a newline   */




          }
        while(inword)
          {if (inword)                    /*  if in a word         */
              { putchar(c);              /*  print the character  */
                  if (IS_UPPER(c)==TRUE)
                  {printf( "%c starts with a capital", c);
                   return c;
                  }


             c = getchar();
              }
          }
}
   /*  print the results  */
     printf("Lines = %d, Words = %d, Characters = %d\n",
               lns, wds, chrs);
}


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University of Hawaii at Manoa, Honolulu (HI), Oahu (Hawaii), Tep Dobry, ee160 EE 160: Homework 3

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by DukeNuke2; 03-24-2011 at 03:38 AM.. Reason: probably saying it wrong for part 1
# 2  
Old 03-25-2011
What's all the code you posted at 2.? Is it yours? Or is it given as "library" functions? I'm asking b/c there are 2 vowel/checking functions.

It would also be great if you can tell us where your problem is in the code.
# 3  
Old 03-26-2011
sorry for the late response but letters.h and letters.c are created and the chrutil.c and chrutil.h are given library. Sorry i reread the hw and misunderstood it that the only file i should include are only letters.h and letters.c, so i am moving prototype i need from chrutil.h and chrutil.c to letters.h and letters.c. The first problem is when i type a word it only reads the first letter of that word (still trying to fix it). the next problem is to add another statement in the while loop in spchk.c to determine the three condition on part 1 of the problem, most likely the adding part should be where the comment says "if not in word and not delimiter" and "if in word and a delimiter". also the delimit can be rewritten so i read what the delimit does from chrutil.c it returns only TRUE if it is a white space and a punctuation. I am kind of clueless where to start for that

---------- Post updated 03-26-11 at 03:43 AM ---------- Previous update was 03-25-11 at 03:04 PM ----------

the function i need to add to this is a function that can read each letter in a word.
a function that can tolerate space. a function that can tell which ends with a vowel or consonant. a function that can tell if the consonant are adjacent.
# 4  
Old 03-26-2011
First of all, you make a common mistake: getchar() returns an int and not a char. This may cause errors in the != EOF condition
Ok, so here's my short approach I would be taken, no guarantuee that it works though Smilie

Code:
int c;
int iscorrect = 1;
int inword  = 0;
int lastvowel = 0; // if it is 1, the previously read char was a vowel
while((c = getchar()) != EOF) {
        if(delimitp((char) c)) {
                if(inword) { // end of word reached
                        (iscorrect == 1 && lastvowel == 1) ? printf(" correct word\n"); : printf(" wrong word\n"); // word had to be correct and the char in front of the delimit had to be vowel
                        inword = 0;
                        iscorrect = 1; //reset
                } else // two or more delimiters, ignore them
                        continue;
        }
        if(!letterp((char) c)) { //word is def wrong
                inword = 1;
                iscorrect = 0;
                putchar(c);
                continue;
        }
        if(!inword) { //first char of word, so we don't check adjacent consonsants here
                inword = 1;
                iscorrect = 1; //we accecpt consonants and vowels here. all other got kicked of in the if before - prob obsolute because we reset it at the delimiters
                if(vowelp((char) c))
                        lastvowel = 1;
                else
                        lastvowel = 0;
                putchat(c);
        } else {
                if(!vowelp((char) c) && lastvowel = 0) //adjacent consonants
                        iscorrect = 0;
                putchar(c);
        }
}

So, I hope this gets the job done Smilie Just a quick summary: First we check for delimiters. If it is the first delimiter and the last char was a vowel (and the word was correct to this point) it is correct. More limiters get ignored.
Then we check what else is there: If it is not a letter, the word is def wrong. But still we put it out.
If it is the first char of a word, we don't care it it is a vowel or consonant, both is ok. But we still need to check so we are able to check for adjacent consonants. This is done via lastvowel.
This User Gave Thanks to disaster For This Post:
# 5  
Old 03-26-2011
yeah ran into a few problem fixed some of it and the only problem i got is on line 29 "iscorrect=0;"
chrutil.h:29: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âvowelpâ

---------- Post updated at 03:29 PM ---------- Previous update was at 03:22 PM ----------

/* file name spchk
* by matthew yee
* login mgy
* date
*/
#include "chrutil.h"
main()
{int c;
int iscorrect = 1;
int inword = 0;
int lastvowel = 0; // if it is 1, the previously read char was a vowel
while((c = getchar()) != EOF)
{
if(delimit((char) c))
{
if(inword) // end of word reached
{
if(iscorrect == 1 && lastvowel == 1) // word had to be correct and the char in front of the delimit had to be vowel

{printf(" correct word\n");}
printf(" wrong word\n");
inword = 0;
iscorrect = 1; //reset}
} else // two or more delimiters, ignore them
continue;
}
if(!letterp((char) c)) { //word is def wrong
inword = 1;
iscorrect = 0;
putchar(c);
continue;
}
if(!inword) { //first char of word, so we don't check adjacent consonsants here
inword = 1;
iscorrect = 1; /*we accecpt consonants and vowels here. all other got kicked of in the if before - prob obsolute because we reset it at the delimiters*/
if(vowelp((char) c))
lastvowel = 1;
else
lastvowel = 0;
putchar(c);
} else {
if(!vowelp((char) c) && lastvowel == 0) //adjacent consonants
iscorrect = 0;
putchar(c);
}
}
}
# 6  
Old 03-28-2011
Payroll Solutions

First of all, you make a common mistake: getchar() returns an int and not a char.
-------
Nancy

---------- Post updated at 02:20 AM ---------- Previous update was at 02:19 AM ----------

I hope this gets the job done Just a quick summary: First we check for delimiters.
-----
Nancy

---------- Post updated at 02:20 AM ---------- Previous update was at 02:20 AM ----------

sorry for the late response but letters.h and letters.c are created and the chrutil.
------
Nancy

---------- Post updated at 02:21 AM ---------- Previous update was at 02:20 AM ----------

sorry for the late response but letters.h and letters.c are created and the chrutil.
--------
Nancy

---------- Post updated at 02:21 AM ---------- Previous update was at 02:21 AM ----------

sorry for the late response but letters.h and letters.c are created and the chrutil.

---------- Post updated at 02:23 AM ---------- Previous update was at 02:21 AM ----------

Sorry i reread the hw and misunderstood it that the only file i should include are only letters.h and letters.c, so i am moving prototype i need from chrutil.h and chrutil.c to letters.h and letters.c.
-------
Nancy

---------- Post updated at 02:24 AM ---------- Previous update was at 02:23 AM ----------

Sorry i reread the hw and misunderstood it that the only file i should include are only letters.h and letters.c, so i am moving prototype i need from chrutil.h and chrutil.c to letters.h and letters.c.
-------
Nancy

---------- Post updated at 02:24 AM ---------- Previous update was at 02:24 AM ----------

Sorry i reread the hw and misunderstood it that the only file i should include are only letters.h and letters.c, so i am moving prototype i need from chrutil.h and chrutil.c to letters.h and letters.c.
-------
Nancy

---------- Post updated at 02:24 AM ---------- Previous update was at 02:24 AM ----------

Sorry i reread the hw and misunderstood it that the only file i should include are only letters.h and letters.c, so i am moving prototype i need from chrutil.h and chrutil.c to letters.h and letters.c.
-------
Nancy

---------- Post updated at 02:24 AM ---------- Previous update was at 02:24 AM ----------

Sorry i reread the hw and misunderstood it that the only file i should include are only letters.h and letters.c, so i am moving prototype i need from chrutil.h and chrutil.c to letters.h and letters.c.
-------
Nancy

---------- Post updated at 02:25 AM ---------- Previous update was at 02:24 AM ----------

Sorry i reread the hw and misunderstood it that the only file i should include are only letters.h and letters.c, so i am moving prototype i need from chrutil.h and chrutil.c to letters.h and letters.c.
-------
Nancy
Payroll Solutions
This User Gave Thanks to nancyparrishnrs For This Post:
# 7  
Old 03-28-2011
Bug thank you

for those who post thanks for your help and yes getchar was part of the problem and apparently return TRUE and return FALSE is also a part of the problem from reading the whole word
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Debian

Getting a better spell checker

Guys I am new to Linux in general and want to know what is the use of the following files-: /usr/share/dict/words /usr/share/dict/words.pre-dictionaries-common Are they used by the spell checker to find potential typos ? If so are there any better larger word lists out there ? I am sure... (2 Replies)
Discussion started by: sreyan32
2 Replies

2. Shell Programming and Scripting

Spell Check

I have this assignment and I am not sure how to start it, I am new any help will be appreciated.... (BASH) Let us say a test is conducted to assess the typing speed for applicants. We need to count # of correctly spelled words and penalize for incorrectly spelled words. score = (# of... (1 Reply)
Discussion started by: shilling
1 Replies

3. Shell Programming and Scripting

spell check program

hi, i need to write a spell check program in bash to find all possible spelling errors in a file or a number of files taken as input using usr/dict/words. whenever the program encounters a spelling error, it must state the line number at which the incorrect spelling has occured and... (1 Reply)
Discussion started by: kratos.
1 Replies

4. UNIX for Dummies Questions & Answers

spell check

# cat wrong.txt thiis is going to be wrong words containing file # aspell list < wrong.txt thiis I want to check only one word and see the first suggestions ("this" in this case). something like... aspell list --one-word thiis --suggest (5 Replies)
Discussion started by: shantanuo
5 Replies

5. UNIX for Advanced & Expert Users

spell

Hi, I found the following line in a shell script. $spell -a < $filename | \ grep -v '@(#)' | sed "s/\'//g" | \ awk '{ if (length($0) > 15 && length($2) > 2) print $2 }' | \ grep -vif $okaywords | \ grep ']' | grep -v ']' | sort -u | \ sed 's/^/ /' > $tempout can... (2 Replies)
Discussion started by: ravi raj kumar
2 Replies

6. Post Here to Contact Site Administrators and Moderators

Spell Check

Administrator/Moderators, I would like to put forth a request rather a suggestion in other words. How about the inclusion of 'SPELL CHECK' tool along with existing submit reply and preview post tools? I believe that would be very much helpful in understanding questions clearly deprived of... (2 Replies)
Discussion started by: matrixmadhan
2 Replies
Login or Register to Ask a Question