Thread: Search/Glossary Tool

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    7

    Search/Glossary Tool (Need Urgent Help)

    Hello everyone.

    My current question is about coding a search tool becuase I want to make a program that can function as a dictionar/glossary. What will be the appropiate code to make a glossary of terms that the user can type a word and the program seach for matches just like a computer dictionary?

    Please help!
    Last edited by ianelchino; 10-05-2005 at 07:07 PM.

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    2
    It depends upon how you are planning to store data. For fast search robust algorithms will be required. Can you tell me what or how you plan to store the data?

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    7
    Thank you for replying.

    The problem is im somewhat new to C. When i planned doing it I thought on all the PC dictionaries available, so I figured I could do it. Isnt there a way to store terms and definitions?
    BTW I do not need it to be very fast for now, I just want it to work. : )

    Can you tell me what algorithm I'll be using?
    Last edited by ianelchino; 10-05-2005 at 07:08 PM.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    2
    Population of this world is tooo much... There is a high probablity that several people will be in need of some system, hence many will be ingaged in development of it.

    Anyway, since you are new to C first learn how to store records in C (i.e., writing, reading records etc). Then learn some theory on file indexing etc. That will surely help.

    Any more confusions please ask...

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    7
    Do you know specific functions or the name of the algorithms that are needed. This way I can find more information. Just so you know im trying to copy all the terms of my chemistry textbok glossary and make a computer glossary using this terms.

  6. #6
    Registered User 2600's Avatar
    Join Date
    Mar 2005
    Posts
    2
    In a very simple way what you can do is to create a record like, -

    Code:
    struct Glossary{
        char term[20];
        char deatils[256];
    }
    Now use it to store/retrive in/from file.

    But honestly, you need to know some good searching/sorting algorithms (if you need to use own file based database), indexing of file. Like consider this, -


    I have a file (say student.dat) containing various records. But in every record I have a unique key (like if record is student details then his enrollment number). Now If I have to search for a particulars students record I will have to search thrugh whole file. Another way is to make an another file say index.dat in which I will store enrollment number and its location in file. Also every time when I will add a record to student.dat file I will save the enrollement number with location in index.dat such that records in index.dat are in sorted order.

    Now if I have to search for a particular student's record it will be easy as I will use binary search on index.dat to find the location of record inside the file and goto that location and read the record.


    Got it?

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    7
    I more or less got it. What does struct do? And what algorithm will i need so the program can find the word being searched for?

  8. #8
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    Quote Originally Posted by ianelchino
    I more or less got it. What does struct do? And what algorithm will i need so the program can find the word being searched for?
    You need to learn the language fundamentals before you can even attempt this.

  9. #9
    Registered User
    Join Date
    Oct 2005
    Posts
    1
    On this subject. I'm coding a dictionary (it's rather large... few hundred terms.) I seem to be having trouble with compound words, as the dictionary always outputs "Not found" when a compound word is typed in. Could anyone help me out with this? Here's what I got for now, it's a tad bit messy, I apologize for any confusion it might cause.
    Code:
    //Attempt at making a faster dictionary program using binary search
    
    #include <stdio.h>
    
    struct entry
    {
                char word[100];
                char definition[200];
                };
                            
                int compareStrings (const char s1[], const char s2[])
                {
                    int i = 0, answer;
                    while (s1[i] == s2[i] && s1[i] != '\0'&& s2[i] != '\0') 
                    ++i;
                    
                    if (s1[i] < s2[i])
                    answer = -1;
                    else if (s1[i] == s2[i])
                    answer = 0;
                    
                    else
                        answer = 1;
                    
                    return answer;
                    }
                    
                    
                    int lookup (const struct entry dictionary[], const char search[], const int entries)
                    
                    {
                        int low = 0;
                        int high = entries - 1;
                        int mid, result;
                        int compareStrings (const char s1[], const char s2[]);
                        
                        while (low <= high)
                        {
                              mid = (low+high) / 2;
                              result = compareStrings (dictionary[mid].word, search);
                              
                              if (result == -1)
                                 low = mid + 1;
                              else if (result == 1)
                                   high = mid - 1;
                              else
                                  return mid; 
                                  }
                                  return -1;
                                  } 
                                    int main (void)
              {
                  const struct entry dictionary[200] =
                  { { "absolute zero", "The zero point on the Kelvin temperature scale, equivalent to -273°C; all molecular motion theoretically stops at this temperature."},
                    { "accepted value", "A quantity used by general agreement of the scientific community."},
                    { "accuracy", "The closeness of a measurement to the true value of what is being measured."},
                    { "acid", "A compound containing hydrogen that ionizes to yield hydrogen ions (H+) in water."},
                    { "acid dissociation constant", "(Ka) The ratio of the concentration of the dissociated form of an acid to the undissociated form; stronger acids have large Ka values than weaker acids."},
                    { "acidic solution", "Any solution in which the hydrogen-ion concentration is greater than the hydroxide-ion concentration."},
                    { "activated complex", "An unstable arrangement of atoms that exists momentarily at the peak of the activation energy barrier; it represents an intermediate or transitional structure formed during the course of a reaction."},
                    { "activation energy", "The minimun energy colliding particles must have in order to react."},
                    { "activity series of metals", "A table listing metals in order of decreasing activity."},
                    { "actual yield", "The amount of product that forms when a reaction is carried out in the laboratory."},
                    { "addition reaction", "A reaction in which a substance is added at the double bond of an alkene or at the triple bond of an alkyne."},
                    { "alcohol", "An organic compound having an -OH (hydroxyl) group; the general structure R-OH."},
                    { "aldehyde", "An organic compound in which the carbon of the carbonyl group is joined to at least one hydrogen; the general formula is RCHO."},
                    { "aliphatic compound", "A hydrocarbon compound that does not contain a ring structure."},
                    { "alkali metal", "Any metal in group 1A of the periodic table."},
                    { "alkali earth metal", "Any metal in group 2A of the periodic table."},
                    { "alkaline solution", "A basic solution."},
                    { "alkane", "A hydrocarbon containing only single covalent bonds; alkanes are saturated hydrocarbons."},
                    { "alkene", "A hydrocarbon containing one or more carbon-carbon double bonds; alkenes are unsaturated hydrocarbons."},
                    { "alkyl group", "A hydrocarbon substituent; methyl (CH3) is an alkyl group."},
                    { "alkyl halide", "A halocarbon in which one or more halogen atoms are attached to the carbon atoms of an aliphatic chain."},
                    { "alkyne", "A hydrocarbon containing a carbon-carbon triple bond; alkynes are unsaturated hydrocarbons."},
                    { "allotrope", "A molecular form of an element that exists in two or more different forms in the same physical state; oxygen, O2, and ozone O3 are allotropes of the element oxygen."},
                    { "alpha particle", "A positively charged particle emitted from certain charged nuclei; it consists of two protons and two neutrons and is identical to the nucleus of a helium atom."},
                    { "alpha radiation", "Alpha particles emitted from the radioactive source."},
                    { "amino acid", "An organic compound having amino (-NH2) and carboxylic acid (-COOH) groups in the same molecule; proteins are made of the twenty naturally occurring amino acids."},
                    { "amphoteric", "A substance that can act both as an acid and a base; water is amphoteric."},
                    { "amplitude", "The height of a wave from the origin to the crest."},
                    { "amorphous solid", "A term used to describe a solid that lacks an ordered internal structure; denotes a random arrangement of atoms."},
                    { "analytical chemistry", "The study of the composition of substances."},
                    { "anion", "Any atom or group or group of atoms with a negative charge."},
                    { "anode", "The electrode at which oxidation occurs."},
                    { "antibonding orbital", "A molecular orbital whose energy is higher than that of the atomic orbitals from which it is formed."},
                    { "aquous solution", "A solution in which the solvent is water."},
                    { "arene", "Any member of a special group of unsaturated cyclic hydrocarbons."},
                    { "aromatic compound", "A name originally given to the arenes because many of them have pleasant odors."},
                    { "aryl halide", "A halocarbon in which one or more halogens are attached to the carbon atoms of an arene ring."},
                    { "asymmetric carbon", "A carbon atom that has four different groups attached."},
                    { "atom", "The smallest particle of an element that retains the properties of that element."},
                    { "atomic emission spectrum", "The pattern of frequencies obtained by passing light emitted by atoms of an element in the gaseous state through a prism; the emission spectrum of each element is unique to that element."},
                    { "atomic mass", "The weighted average of the masses of the isotopes of an element."},
                    { "atomic mass unit", "A unit of mass equal to one-twelth the mass of a carbon-12 atom."},
                    { "atomic number", "The number of protons in the nucleus of an atom of an element."},
                    { "atomic orbital", "A region in space around the nucleus of an atom where there is a high probability of finding an electron."},
                    { "atomic radius", "One-half the distance between the nuclei in a molecule consisting of identical atoms."},
                    { "atmospheric pressure", "The pressure exerted by air molecules in the atmosphere sorrounding the earth, resulting from collisions of air molecules with objects."},
                    { "Aufbau principle", "Electrons enter orbitals of lower energy first."},
                    { "Avogadro's hypothesis", "Equal volumes of gases at the same temperature and pressure contain equal numbers."} };
                    
                    int entries = 50;
                    char word[100];
                    int entry;
                    int lookup (const struct entry dictionary[], const char search[], const int entries);
                    
                    printf ("Enter desired term: ");
                    scanf ("%s", word);
                    
                    entry = lookup (dictionary, word, entries);
                    
                    if (entry != -1)
                       printf ("%s\n", dictionary[entry].definition);
                    else
                        printf("Sorry, term could not be found\n");
                        getchar();
                        getchar();
                        return 0;
                        }
    Last edited by NightmareHunter; 10-10-2005 at 08:10 AM.

  10. #10
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    Well, the problem that you are asking about......scanf will read until it hits a whitespace, meaning you cant use it (the way you are now) to read in multiple words.

    Example:

    scanf("%s",some_string);

    if the user enters "hello world" only "hello" will be read into the variable "some_string".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. grep tool
    By George2 in forum Tech Board
    Replies: 7
    Last Post: 02-10-2008, 02:12 AM
  2. 3D Network Analysis Tool
    By durban in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 11-08-2005, 06:33 PM
  3. Source Code Analysis Tool?
    By Sereby in forum C Programming
    Replies: 4
    Last Post: 02-18-2005, 09:11 AM
  4. DX Texture Tool
    By spoon_ in forum Tech Board
    Replies: 0
    Last Post: 03-08-2004, 05:19 PM
  5. O/R Mapping tool like Apple has.....for .NET?!?!
    By gicio in forum C# Programming
    Replies: 0
    Last Post: 08-29-2003, 04:20 AM