1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Dictionar

Discussion in 'C++' started by gpk kishore, Nov 13, 2011.

  1. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    Please I want the program for Implementing Dictionary using arrays
     
  2. ophelia.2010

    ophelia.2010 New Member

    Joined:
    Oct 18, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    london
    You can do it using a 2D array.Obviously there would be more words in a dictionary but I'll just do for one:

    #include<stdio.h>
    #include<string.h>
    main()
    {
    char A[100][100],B[15];
    int c;
    strcpy(A,"Hardware-Physical and tangible components of a computer");
    //You will have to do for all those words in dictionary
    printf("Enter the meaning of the word to be found \n");
    scanf("%s",B);
    c=strlen(B);//Finding the length of the word whose meaning is to be found
    for(i=0;i<100;i++)
    //Assume that you have stored 100 words out of which hardware is one
    {
    if(strncmp(B,A,c)==0)//comparing the words
    printf("%s ",A);
    }
    }
    note:strncmp() is used to compare the first n letters of a string.when we count the letters in a hardware using strlen(), it comes upto 8. So the first eight letters of the main character array where you store all the words along with their meaning are checked. If it matches , the meaning is displayed. There's no function called strncmpi to ignore the case(lower or upper) , you can't use it like strcmpi-so notify the user to enter the word with the first letter alone in upper case(for this particular program code). It depends on how you initialise the main array in the beginning!!!

    Hope this was useful!!!
     

Share This Page