标题:strcmp二维数组字典程序纠错
只看楼主
Timber
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2010-1-31
结帖率:71.43%
 问题点数:0 回复次数:4 
strcmp二维数组字典程序纠错
Write a program that implements finnish-english dictionary
using 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 编辑 ]
搜索更多相关主题的帖子: dictionary 字典 word 
2010-04-22 14:49
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
得分:0 
Word没有初始化指向
2010-04-22 14:54
Timber
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2010-1-31
得分:0 
回复 2楼 ychf890225
请问怎么初始化指向啊,我是菜鸟,不要意思

But here I am
2010-04-22 14:57
Timber
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2010-1-31
得分:0 
自顶。。就这么沉了。。

But here I am
2010-04-23 15:30
我菜119
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:938
专家分:1756
注 册:2009-10-17
得分:0 
word你没有给它分配相应的内存空间,你可以使用动态分配函数malloc()就可以了!
比如说:word=(char*)malloc(count);

愿用余生致力编程
2010-04-23 21:21



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-304025-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.683114 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved