Discussion in 'C++' started by gpk kishore, Nov 13, 2011.
Please I want the program for Implementing Dictionary using arrays
You can do it using a 2D array.Obviously there would be more words in a dictionary but I'll just do for one:
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");
c=strlen(B);//Finding the length of the word whose meaning is to be found
//Assume that you have stored 100 words out of which hardware is one
if(strncmp(B,A,c)==0)//comparing the words
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!!!
Separate names with a comma.