Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Feb 19th, 2008, 3:58 PM   #1
bankster
Oskilliet Warlord
 
bankster's Avatar
 
Join Date: Feb 2008
Location: Bkk,Thailand
Posts: 3
Rep Power: 0 bankster is on a distinguished road
Send a message via MSN to bankster
Exclamation help me please : text file based dictionary with c

im just a student in high school
my father introduce me to computer programming
and I think I interested in develop a simple
text file based dictionary

I select C in implementation
but I don't know any way to start
any knowledge that I must know before
writing it .?

now I can deal with string , file ,
but I don't know much about data structure

furthermore , if I can search the word through
the CSV file (word,meaning) then
I need to sort word in file
in a format of dictionary.

could anyone give me any suggession
to get through my problem ?
bankster is offline   Reply With Quote
Old Feb 21st, 2008, 9:38 AM   #2
wolfpack
Mentally Challenged
 
Join Date: Oct 2007
Location: Japan
Posts: 6
Rep Power: 0 wolfpack is on a distinguished road
Re: help me please : text file based dictionary with c

How you go about programming this will depend on the structure of the dictionary file.
Can you post a sample of the dictionary?
__________________
I don't need no signature.
wolfpack is offline   Reply With Quote
Old Feb 21st, 2008, 9:58 AM   #3
bankster
Oskilliet Warlord
 
bankster's Avatar
 
Join Date: Feb 2008
Location: Bkk,Thailand
Posts: 3
Rep Power: 0 bankster is on a distinguished road
Send a message via MSN to bankster
Re: help me please : text file based dictionary with c

Quote:
Originally Posted by wolfpack View Post
How you go about programming this will depend on the structure of the dictionary file.
Can you post a sample of the dictionary?
yes, I decided to use CSV as a dictionary file structure.

like this

word,notation
word2,notation2

thanks for your rep
I keep waiting
bankster is offline   Reply With Quote
Old Feb 21st, 2008, 10:44 AM   #4
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: help me please : text file based dictionary with c

Just read the CSV file line by line in a loop. You said you know about files so I assume you already know how to do that. After reading a line you need to separate the two words then compare the first word with the word you want to find. There are a couple of standard string functions you could use to do that.

1) use strchr() to locate the comma, then replace it with a 0 string null terminator.
char line[255] = "word,notation";
// search for the comma
char* firstWord = NULL;
char* secondWord = NULL;
int spot = strchr(line,',');
if( spot > 0)
{ 
    line[spot] = 0; // null terminate
    firstWord = line;
    secondWord = line + spot + 1;
}

Anter way (and simpler) is to use strtok
char line[255] = "word,notation";
// search for the comma
char* firstWord = strtok( line, ",");
char* secondWord = strtok( NULL, ",");
Ancient Dragon is offline   Reply With Quote
Old Feb 24th, 2008, 7:56 AM   #5
bankster
Oskilliet Warlord
 
bankster's Avatar
 
Join Date: Feb 2008
Location: Bkk,Thailand
Posts: 3
Rep Power: 0 bankster is on a distinguished road
Send a message via MSN to bankster
Exclamation Re: help me please : text file based dictionary with c

Hi, now I can search through csv file line by line
thanks so much for your suggestion above.

so code is like this
c Syntax (Toggle Plain Text)
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main(int argc,char *argv[])
  5. {
  6. FILE *fp;
  7. char line[1000];
  8.  
  9. char *word;
  10. char *mean;
  11. int found=0;
  12.  
  13.  
  14. fp=fopen("dict.dat","r");
  15.  
  16. while(fp!=NULL && (!feof(fp)))
  17. {
  18. while(fgets(line,1000,fp))
  19. {
  20. word=strtok(line,",");
  21. mean=strtok(NULL,",");
  22. if((strcmp(word,argv[1]))==0)
  23. {
  24. printf("%s",mean);
  25. found=1;
  26. break;
  27. }
  28.  
  29.  
  30. }
  31. }
  32. if(found==0)
  33. printf("can't find word in database file\n");
  34.  
  35.  
  36. return 0;
  37. }

but in this case , my dict is show the meaning
if only input word = word in database every each characters.

but in the real world , dictionary give me more
dictionary can give a word that also like an input word
such as

CSV - example
bankster,a student in one highschool of the world
programming_forums_org,the land of programmng

I try to give input like this
./dictionary bank

my current dictionary search through the line
and string compare with the word that I separated from the line
the result !=0 so it's can't find this word in database .

actually , thing that I need this program to work for me
is to listing the word that LIKE or possible word in database
for user.

could you give me any suggestion like before?

and finally I hope that anyone wouldn't think
this just a school homework .
I don't study computer programming at school
but I love it , my father introduce it to me.

something that I will do for my dictionary
- sort every word in csv file alphabetically A-Z
- add word into file
- append external csv file to current file and sort them
- dictionary web application

thank you
p.s. sorry for my bad English , I am Thai .
bankster is offline   Reply With Quote
Old Feb 24th, 2008, 3:22 PM   #6
WaltP
Programmer
 
Join Date: Oct 2007
Posts: 39
Rep Power: 0 WaltP is on a distinguished road
Re: help me please : text file based dictionary with c

Instead of using strcmp() you need to use strncmp(). Get the length of the word you are looking for using strlen() and use that value for the length. That way bank will match with
bank
banker
banking
bankster

etc
__________________
Testing 001 010 011 100....
WaltP 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
Help with fstream to a text file rhm54 C++ 6 Oct 22nd, 2007 10:39 PM
C++ IDEs/Java Libraries/Making a Text Based Game! Tsar_of_Cows Java 17 Jun 22nd, 2007 2:52 PM
Dynamic form from text file. randum77 Visual Basic .NET 4 Apr 24th, 2007 12:39 PM
Adding more info to a text file without erasing crawforddavid2006 C# 2 Apr 11th, 2007 3:10 PM
How to read unknown total of int data from text file to a 2-dim array in C ladyscarlet99 C 2 Sep 9th, 2005 3:28 AM




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

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