Dictionary Program in C language

Hello Guys, Today I am going to post a nice dictionary program, developed in "C" Language, by using 2-Dimensional Array. Following is the code and output  of the program.

1. Source Code of the Program: 

#include<stdio.h> //Standard Input-Output, Header File
#include<conio.h> //Console input-Output Header File
#include<string.h> // Header file for String Handling
#include<graphics.h> // Header File for graphics-implementation

int g1,g2;    //global variable for storing position to fetch the record.
//Functions for each alphabet to store and fetch word-meanings.
char A()
{  char x[50][100]={"aberrant=deviating ","abate=subside/diminish","abominable=unequivocally detestable; loathsome.","abscond=to leave hurriedly and secretly.","abyssopelagic=of, like or pertaining to the depths of the ocean.","absolution=the act of absolving or the state of being absolved.","acatalepsy=incomprehensibility.","accoutrements=personal clothing, accessories.","accomplishment=achievement","acolyte=one who assists the celebrant in the performance of liturgical rites.","acquiesce=to consent or comply passively or without protest.","adumbrate=to give a sketchy outline of.","aesthetic=relating to the philosophy or theories of aesthetics.","affable=easy and pleasant to speak to; approachable.","affinity=a natural attraction, liking, or feeling of kinship.","affect=impact","agape=love as revealed in Jesus, seen as spiritual and selfless and a model for humanity.",
"archipelago=a large group of islands.","argent=a metal tincture used in heraldry to give. ",
 "axiology =the study of the nature of values and value judgments.", "azure=a light purplish blue."};
  return x[g1][g2];
}

char B()
{  char x[50][40]={"begule=tempt","bailiwick=authority","banausic=merely mechanical; routine","bauble=a showy.", "bereft=deprived of something","betwixt=between.","bilious=relating to","bliss=extreme happiness"};
  return x[g1][g2];
}

char C()
{  char x[50][40]={"cachinnation=a loud, hard","cabal=a conspiratorial group .","compensate=settled","cacology=bad choice or use of words.","cacophony=jarring, discordant sound","catachresis=the incorrect","cataclysmic=severely destructive.","completent=skilled","confirm=comply","commends=praise","comply=follow","comprehensive=broad","conjecture=conclusion","commodity=goods","censure=disapproval"};
  return x[g1][g2];
}

char D()
{  char x[50][40]={"dearth=a scarce supply;","debacle=a sudden","decadence=period of deterioration","defenestrate=to throw out ofa window","defile=to make filthy or dirty;","delibarate=knowing","device=gadget","device=develop","dingy=dirty","data=facts","decisive=crucial"};
  return x[g1][g2];
}

char E()
{  char x[50][40]={"eburnine=pertaining to " , "ecdysiast=a striptease artist." , "effervescence=to give off bubbles" , "efficacious=producing or capable" , "empress=the woman ruler of an empire." , "ecstasy=intense joy or delight." , "effect=result" , "enmity=hostality" , "exempt=free","emigrant=travellor","expendient=tactic","enterprise=venture"};
  return x[g1][g2];
}

char F()
{  char x[50][40]={"febrile=relating to","faux pas=a social blunder.","facetious=playfully jocular","feral=in a wild state" ,"formidable=arduous","flexible=elastic","foil=thwart","founder=fail","feign=imitate","filial=loyal"};
  return x[g1][g2];
}

char G()
{  char x[50][40]={"gratify=satisfy","guise=costume","grievous=serious"};
  return x[g1][g2];
}

char H()
{  char x[50][40]={"herenditary=genetic","humiliate=dishonour","horizontal=parallel","harmonious=peaceful","hazardous=dangerous"};
  return x[g1][g2];
}

char I()
{  char x[50][40]={"insure=indemnify","imply=to mean","impose=compel","inflict=impose","intricate=complicated","irrigate=sprinkle","insulate=shield","immigrant=settler","isolate=separate"};
  return x[g1][g2];
}

char J()
{  char x[50][40]={"jejune=not interesting, dull, empty","jocularity=joking speech or behavior","jovial=full of or showing high-","juvenescent=becoming young or youthful."};
  return x[g1][g2];
}

char K()
{  char x[50][40]={ "kaleidoscope=a series of changing ","katabatic=relating to.","kerfuffle=a disorderly ","kismet=fate; fortune."};
  return x[g1][g2];
}

char L()
{  char x[50][40]={"lachrymose=weeping","lackadaisical=lacking spirit"};
  return x[g1][g2];
}

char M()
{  char x[50][40]={"machination=the act of plotting.","majuscule=a large letter"};
  return x[g1][g2];
}

char N()
{  char x[50][40]={"nadir=the lowest point.", "nebulous=cloudy, misty","necromancy=black magic; sorcery"};
  return x[g1][g2];
}

char O()
{  char x[50][40]={"obfuscate=to render indistinct","obloquy=verbal abuse of a person"};
  return x[g1][g2];
}

char P()
{  char x[50][40]={"palliative=tending or serving","panacea=a remedy for all diseases"};
  return x[g1][g2];
}

char Q()
{  char x[50][40]={"quiddity=the real nature of a thing","quidnunc =a busybody; a nosy person."};
  return x[g1][g2];
}

char R()
{  char x[50][40]={ "rapscallion=a rascal; a scamp.","ravenous=extremely hungry; voracious"};
  return x[g1][g2];
}

char S()
{  char x[50][40]={"sagacity=the quality of being discer","salient=strikingly conspicuous"};
  return x[g1][g2];
}

char T()
{  char x[50][40]={"taciturn=habitually untalkative","tarradiddle=a petty falsehood"};
  return x[g1][g2];
}

char U()
{  char x[50][40]={"ululate=to howl","usurp=to take over or occupy"};
  return x[g1][g2];
}

char V()
{  char x[50][40]={"valley= hills","verisimilitude=the quality"};
  return x[g1][g2];
}

char W()
{  char x[50][40]={"Weanling=a child or animal newly","willow=the wood of any of these tree"};
  return x[g1][g2];
}

char X()
{  char x[50][40]={"xanthippe=the wife of Socrates"};
  return x[g1][g2];
}

char Y()
{  char x[50][40]={"yeoman=an attendant, servant","Yesternight=last night."};
  return x[g1][g2];
}

char Z()
{  char x[50][40]={"zaftig=full-bosomed.","zeitgeist=the spirit of the time."};
  return x[g1][g2];
}
//In this function, You can add as much as word as you want. But you should change the size //for array for each alphabet, from x[50][100] to x[a][b]- here a= no. of words to be stored //of that alphabet. b- length  of description, or meaning with word.

void main() //Main function, - Starting Point for execution of program.
     char s1[10],s2[50][30],sw,flag,re;
     int i,j,hi,hj,sl,sl2,temp=1; //hi-hold i,hj-hold j,sl-string length(enter),sl2-string rows no.

   clrscr();
   loop:
   textcolor(9);
   cprintf("Enter a string=");
   textcolor(12);
   cscanf("%s",s1);
   printf("\n");
   textcolor(15);

  sw=s1[0];
   for(g1=0;g1<50;g1++)
   { for(g2=0;g2<40;g2++)

     switch(sw)
     { case'a':
       s2[g1][g2]=A();
       break;

       case'b':
       s2[g1][g2]=B();
       break;

       case'c':
       s2[g1][g2]=C();
       break;
       case'd':
       s2[g1][g2]=D();
       break;
       case'e':
       s2[g1][g2]=E();
       break;
       case'f':
       s2[g1][g2]=F();
       break;
       case'g':
       s2[g1][g2]=G();
       break;
       case'h':
       s2[g1][g2]=H();
       break;
       case'i':
       s2[g1][g2]=I();
       break;
       case'j':
       s2[g1][g2]=J();
       break;
       case'k':
       s2[g1][g2]=K();
       break;
       case'l':
       s2[g1][g2]=L();
       break;
       case'm':
       s2[g1][g2]=M();
       break;
       case'n':
       s2[g1][g2]=N();
       break;
       case'o':
       s2[g1][g2]=O();
       break;
       case'p':
       s2[g1][g2]=P();
       break;
       case'q':
       s2[g1][g2]=Q();
       break;
       case'r':
       s2[g1][g2]=R();
       break;
       case's':
       s2[g1][g2]=S();
       break;
       case't':
       s2[g1][g2]=T();
       break;
       case'u':
       s2[g1][g2]=U();
       break;
       case'v':
       s2[g1][g2]=V();
       break;
       case'w':
       s2[g1][g2]=W();
       break;
       case'x':
       s2[g1][g2]=X();
       break;
       case'y':
       s2[g1][g2]=Y();
       break;
       case'z':
       s2[g1][g2]=Z();
       break;
       default:
       {
       printf("please enter only alphabet\n");
       goto loop; //goto control to the loop, statement, stated above.
       }

     } //Switch case End
       sl2=strlen(s2[g1]);
      if(sl2==0)
      {//printf("%d",g1);
      sl2=g1;g1=40;   //sl-store no of row element
      break;
      }
    }                     //s2-collect string from function
 sl=strlen(s1);

//compare loop
  for(i=0;i<sl2;i++)
   {   temp=1;  //for avoiding repeatation of latter at same position
    for(j=0;s2[i][j]!='=';j++)
     {
       if((s2[i][j]==s1[j])&&(temp==1))  //temp if match then entry
{
  textcolor(14);
  cprintf("%c",s2[i][j]);
  hj=j;

  if(((hj+1)==sl)&& (s2[i][j+1])=='=')
    { flag='a';
      hi=i;
      hj=j;
      printf("\t\t");
      //cprintf(" <=  hi=%d,hj=%d",hi,hj);
      textcolor(15);
    }


       }
     else
       { temp=0;
       printf("%c",s2[i][j]);
       }

     } //j loop
     printf("\n");
     //printf("\n\t%s\n",s2[i]);    //whole string print ,stored in s2

    }// i loop
    textcolor(12);
    if(flag=='a')
     { printf("\n\n");
      cprintf("your searched wordmean => ");
      textcolor(13);
      cprintf("%s",s2[hi]);
      }
    else
    {
     printf("\n");
     cprintf(" try other word");
    }
   printf("\n");
   textcolor(12);
  cprintf("want to continue y/n= ");
  textcolor(11);
  cscanf("%s",&re);
  printf("\n");
 // printf("%s",re);
  if(re=='y'||re=='Y')
  {
  g1=g2=0;
  goto loop;
  }
  else
  exit();
 getch();

}

1. It will be the output of program, after execution:

 2. After searching any word, all related words with that character or word will be displayed and matched characters will be highlighted as : 

 3. Type "y", if you want to continue searching, or "n/N" to exit program.




Post in comment, in case any problem/ error.

Comments

Popular posts from this blog

Components of C language

Decision making using if statement

How to make payment for final certificate, migration, provisional for the students of last semester of ptu?