strcmp二维数组字典程序纠错
Write a program that implements finnish-english dictionaryusing a two dimensional array of char pointers. The array row shall
contain first english word and then finnish word.
hint:
char *dict[??][2] = { ??? };
The words known by the program are set in the array initialization.
Program asks user to enter a word (in english of finnsh) and then searches
the dictionary for that word. If the word is found it diplays
the word in both languages. If word is not found user is notified that word is
not in the dictionary.
hint: use strcmp
User exits the program by entering a line which contains
a single dot.
You can use your own language instead of finnish if you wish.
Use functions to divide your program to smaller units.
------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
char *word;
int i;
char *give[2][2]={{"nice","kaunis"},{"ugly","ruma"}};
printf("please enter a word:");
scanf("%s",word);
printf("\n");
for (i=0;i<=2;i++)
{
if (!strcmp(word,give[i][0]))
{
printf("%s %s\n",word,give[i][1]);
break;
}
}
return 0;
}
[ 本帖最后由 Timber 于 2010-4-22 15:11 编辑 ]