Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 28th, 2008, 12:23 AM   #1
rocketscience
Newbie
 
Join Date: Feb 2008
Posts: 1
Rep Power: 0 rocketscience is on a distinguished road
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
rocketscience is offline   Reply With Quote
Old Feb 28th, 2008, 12:30 AM   #2
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 598
Rep Power: 4 Ancient Dragon is on a distinguished road
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
}
__________________
<<Freelance Programmer>> << Hobby Site>>
Ancient Dragon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC