hi I was wondering if anyone knows how to create a dictionary using ANSI C. I really Dont know where to start...any help is appreciated...

Thanx in advance

If I were you, I'd start by defining exactly what you mean by "dictionary".

first of all thanks for replying...A dictionary from japanse romanji to english and vise versa..and the dictionary data base would be from a single text file....my main prob is how do i get a specific line from that text file
..:D

first of all thanks for replying...A dictionary from japanse romanji to english and vise versa..and the dictionary data base would be from a single text file....my main prob is how do i get a specific line from that text file
..:D

Well what you really need to do is to create a very large HASH TABLE where in a key has two references ie a word types in japanese(key) with references as the languages you would want to translate that into(meanings). You can work out your needs and the resources and then decide as to which method to choose.

I am sending u a copy of program

Attachments
/* Dictionary */

#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

struct node
{
	char data [ 20 ] ;
	char m [ 5 ] [ 20 ] ;
	int mcount ;
	struct node * link ;
} ;

struct node * dic [ 26 ] ;

void add ( char * ) ;
int  search ( char * ) ;
void show( ) ;
void deldic( ) ;

void main( )
{
	char word [ 20 ] , ch ;
	int i ;

	clrscr( ) ;

	while ( 1 )
	{
		clrscr( ) ;
		printf ( "\n\t\tDictionary\n" ) ;
		printf ( "\n\t\t1.Add Word.\n" ) ;
		printf ( "\t\t2.Search Word.\n" ) ;
		printf ( "\t\t3.Show Dictionary.\n" ) ;
		printf ( "\t\t0.Exit." ) ;
		printf ( "\n\n\t\tYour Choice ") ;
		scanf ( "%d", &ch ) ;

		switch ( ch )
		{
			case 1 :

				printf ( "\nEnter any word : " ) ;
				fflush ( stdin ) ;
				gets ( word ) ;
				add ( word ) ;

				break ;

			case 2 :

				printf ( "\nEnter the word to search : " ) ;
				fflush ( stdin ) ;
				gets ( word ) ;
				i = search ( word ) ;
				if ( ! i )
					printf ( "Word does not exists." ) ;
				getch( ) ;

				break ;

			case 3 :

				show( ) ;
				getch( ) ;

				break ;

			case 0 :

				deldic( ) ;
				exit ( 0 ) ;

			default :

				printf ( "\nWrong Choice" ) ;
		}
	}
}

void add ( char * str )
{
	int i, j = toupper ( str [ 0 ] ) - 65 ;
	struct node * r, * temp = dic [ j ], * q ;
	char mean [ 5 ] [ 20 ], ch = 'y' ;

	i = search ( str ) ;
	if ( i )
	{
		printf ( "\nWord already exists." ) ;
		getch( ) ;
		return ;
	}
	q = ( struct node * ) malloc ( sizeof ( struct node ) ) ;
	strcpy ( q -> data, str ) ;
	q -> link = NULL ;

	for ( i = 0 ; tolower ( ch ) == 'y' && i < 5 ; i++ )
	{
		fflush ( stdin ) ;
		printf ( "\n\nEnter the meaning(s) : " ) ;
		gets ( mean [ i ] ) ;
		strcpy ( q -> m [ i ] , mean [ i ] ) ;
		if ( i != 4 )
			printf ( "\nAdd more meanings (y/n) " ) ;
		else
			printf ( "You cannot enter more than 5 meanings." ) ;
		fflush ( stdin ) ;
		ch = getche( ) ;
	}

	q -> mcount = i ;
	if ( dic [ j ] == NULL || strcmp ( dic [ j ] -> data, str ) > 0 )
	{
		r = dic [ j ] ;
		dic [ j ] = q ;
		q -> link = r ;
		return ;
	}

	else
	{
		while ( temp != NULL )
		{
			if ( ( strcmp ( temp -> data, str ) < 0 ) && ( ( strcmp ( temp -> link -> data, str ) > 0 ) ||
											temp -> link == NULL ) )
			{
				q -> link = temp -> link ;
				temp -> link = q ;
				return ;
			}
			temp = temp -> link ;
		}
	}
}

int search ( char *str )
{
	struct node *n ;
	char temp1 [ 20 ] ;
	char temp2 [ 20 ] ;
	int i ;

	n = dic [ toupper ( str [ 0 ] ) - 65 ] ;
	strcpy ( temp2, str ) ;
	strupr ( temp2 ) ;

	while ( n != NULL )
	{
		strcpy ( temp1, n -> data ) ;

		if (  strcmp ( strupr ( temp1 ), temp2 ) == 0 )
		{
			printf ( "\n%s\t\t%s", n -> data, n -> m [ 0 ] ) ;
			for ( i = 1 ; i < n -> mcount ; i++ )
				printf ( "\n\t\t%s", n -> m [ i ] ) ;
			return 1 ;
		}
		n = n -> link ;
	}
	return 0 ;
}

void show( )
{
	struct node *n ;
	int i, j ;

	printf ( "Word\t\tMeaning\n" ) ;
	for ( i = 0 ; i <= 30 ; i++ )
		printf ( "-" ) ;


	for ( i = 0 ; i <= 25 ; i++ )
	{
		n = dic [ i ] ;
		while ( n != NULL )
		{
			printf ( "\n%s\t\t%s", n -> data, n -> m [ 0 ] ) ;
			for ( j = 1 ; j < n -> mcount ; j++ )
				printf ( "\n\t\t%s", n -> m [ j ] ) ;
			n = n -> link ;
		}
	}
}

void deldic( )
{
	struct node *n, *t ;
	int i ;

	for ( i = 0 ; i <= 25 ; i++ )
	{
		n = dic [ i ] ;
		while ( n != NULL )
		{
			t = n -> link ;
			free ( n ) ;
			n = t ;
		}
	}
}

I am sending u a copy of program

thank you very much for the help!! it really did!!..thank you ur a life saver!!..:D

surender ur program is working but there is still a problem that we have to add words in the dictionary...this can also be possible using simple coding if a person have knowledge about structure....but i want to know that is there any way in which we can add words without a mannual adding?its very urgent for me?plz reply?

The earlier posts are from 2009, so I doubt they will answer your questions.

You need to start a new thread with your problem, and let this one be buried, again. ;)

This article has been dead for over six months. Start a new discussion instead.