[ back to toc ]

writing a program that translate words

Date: 2002/01/29 08:54

Q:
hello

i have to write a program that translate words in English and other
language.the question is as follows:
write a program which allows the user to translate words from one language
to another. the program must allow the user to enter up to 100 pairs of
words in english and other language,eg:
enter word 1 in English: dog
enter word 1 in other language: hond
enter word 2 in English:fish
enter word 2 in other language:vis
etc..
each word must be up to 20 characters. after all words have been entered,
the program must enter a loop which:
allows the user to enter an english word, or type nothing to exit the
program;
searches through the English words in memory(using stricmp)to find a match
and
prints the corresponding word in the other language if a match is found
example:
Enter English word: fish
"fish translate to "vis"

my program is as follows:

#define MAXWORDS 100
#define WORD_LEN 20

main ()
{
char word1[WORD_LEN],
word2[WORD_LEN];
int word, /* no. of words in english */
i, /* loop counter- english words*/
words, /* no. of words in other lang*/
j; /*loop counter- other lang */

/* Input no. of words in eng */
printf("Enter number of words in english
(max%d)): ",MAXWORDS);
do
scanf"%d",&word);
while(word < 1 || word > MAXWORDS);
printf("Enter number of words in other
(max %d)): ",MAXWORDS);
do
scanf ("%d", &words);
while (words < 1 || words > MAXWORDS);

/* Input words */
for(i = 0; i < word; i++)
for(j = 0; j < words; j++)
{
printf ("Enter word % in English: ", i += 1);
gets(word1);
printf("Enter word %d in other language: ",
j + 1);
printf(word2);

/* Input english word */
printf ("Enter English word: ");
gets(word1);

my problem is that i cannot make the program to translate the right
english word to the right other word and make the loop produce the right
answer. my other problem is i don't know how to use stricmp. please help.

A:
man strcmp

STRCMP(3) Linux Programmer's Manual STRCMP(3)

NAME
strcmp, strncmp - compare two strings

SYNOPSIS
#include <string.h>

int strcmp(const char *s1, const char *s2);

int strncmp(const char *s1, const char *s2, size_t n);

DESCRIPTION
The strcmp() function compares the two strings s1 and s2.
It returns an integer less than, equal to, or greater than
zero if s1 is found, respectively, to be less than, to
match, or be greater than s2.

The strncmp() function is similar, except it only compares
the first n characters of s1.

RETURN VALUE
The strcmp() and strncmp() functions return an integer
less than, equal to, or greater than zero if s1 (or the
first n bytes thereof) is found, respectively, to be less
than, to match, or be greater than s2.

CONFORMING TO
SVID 3, POSIX, BSD 4.3, ISO 9899

SEE ALSO
bcmp(3), memcmp(3), strcasecmp(3), strncasecmp(3), str­
coll(3)

April 11, 1993 1

[ back to toc ]