![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2008
Posts: 1
Rep Power: 0
![]() |
Spell-checker in C
Hi,
I'm new to programming and have been trying hard to create a spell-check program but to no avail. What I'm trying to code is a program that prints out list of all words in an input file which are not present in another file (dictionary). And if a word occurs a certain number of times (say 3 or more times) and is not in the dictionary file, i'm trying to save it to a new personal dictionary file which i display to the user at the end. there is no user input involved. i'm doing this because basically i'm trying to learn how to dynamically allocate all arrays using malloc. i also want to use fscanf to read in words from the files. the only thing i've really gotten done confidently is the function which converts all characters to lowercase and removes commas, periods and colons etc.. Here it is: void function1(char *string1, char *string2)
{
int i, j=0;
char k;
for (i=0; i<strlen(string1); i++)
{
k = string1[i];
if (((k>='a') && (k<='z')) || (k=='\''))
string2[j++] = string1[i];
else if ((k>='A') && (k<='Z'))
string2[j++] = string1[i] - 'A' + 'a';
}
string2[j] = '\0';Could anybody help me with the rest of this code please???? Last edited by Ancient Dragon; Feb 28th, 2008 at 12:24 AM. Reason: corrected code tags |
|
|
|
|
|
#2 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 598
Rep Power: 4
![]() |
Re: Spell-checker in C
lines 8-10 can be simplified like this:
if( isalpha(string1[i]) )
string2[j++] = tolower(string1[i]);line 5: strlen() function is being called on every iteration of that loop. Set a variable to the length before the loop starts then use that varaible in the loop. int len = strlen(string1);
for(i = 0; i < len; i++)
{
// blabla
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grammar Checker | binodbdrchand | Existing Project Development | 3 | Aug 21st, 2007 6:17 AM |
| Spell Checker | metsfan | Java | 2 | Mar 5th, 2007 8:17 PM |
| simple password checker | RemoteC2 | C++ | 13 | Aug 10th, 2006 6:07 PM |
| Some Nifty Code | Sane | Python | 2 | May 10th, 2005 6:56 AM |
| YAHOO! ID Checker | Cipher | Visual Basic | 5 | Mar 27th, 2005 4:36 PM |