GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Nov-2004, 11:57
Tanag Tanag is offline
New Member
 
Join Date: Nov 2004
Posts: 2
Tanag is on a distinguished road

Comparing strings in C


Hello, I'm new here and I have a question.

I'm doing this project for school and I need to compare a word in a file to a list fo words in a dictionary. It's basically a crappy spell checker.

Anyways, I isolate the words in the file one by one and store them in an array of characters. This works fine, however when I comparer it to the dictionary file it says they never match up, though I know they do. So every word is printed as a typo.
The dictionary file is a list of sequential words, one per line. I think this is what is getting me. As when it reads the dictionary file it grabs the new line character as well, then it doesn't compare properly with strcmp. Would this theory be right?
I tried appending an extra '\n' to the end of each word as I grab it from the file, but that didn't work. neither did adding a NULL.

Any help would be appreciated.
  #2  
Old 26-Nov-2004, 12:52
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,712
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Tanag
Hello, I'm new here and I have a question.

I'm doing this project for school and I need to compare a word in a file to a list fo words in a dictionary. It's basically a crappy spell checker.

Anyways, I isolate the words in the file one by one and store them in an array of characters. This works fine, however when I comparer it to the dictionary file it says they never match up, though I know they do. So every word is printed as a typo.
The dictionary file is a list of sequential words, one per line. I think this is what is getting me. As when it reads the dictionary file it grabs the new line character as well, then it doesn't compare properly with strcmp. Would this theory be right?
I tried appending an extra '\n' to the end of each word as I grab it from the file, but that didn't work. neither did adding a NULL.

Any help would be appreciated.


Post your code.

Regards,

Dave
  #3  
Old 28-Nov-2004, 18:07
Tanag Tanag is offline
New Member
 
Join Date: Nov 2004
Posts: 2
Tanag is on a distinguished road
I had to hand it in already. Thanks for the thought though!
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB 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
I am reviewing Arrays and need help converting some strings to arrays jenmaz C Programming Language 22 22-Nov-2004 23:26
comparing strings yarons C Programming Language 6 19-Oct-2004 21:03
Including Maps and strings?? maddie C++ Forum 17 05-Jul-2004 06:25
help on comparing structs nusstu C Programming Language 4 03-Apr-2004 02:22
How do you compare two strings? soccer022483 C++ Forum 9 22-Mar-2004 14:45

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:28.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.