佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

12
返回列表 发新帖
楼主: callmebrandon

很急!!! 求各位大大帮忙!!!

[复制链接]
 楼主| 发表于 10-9-2008 12:22 AM | 显示全部楼层
有很多地方还是undeclare,可以帮我改一下??
还有variable in function有问题对吗?
因为pointer的事??帮我看一下好吗?
回复

使用道具 举报


ADVERTISEMENT

发表于 10-9-2008 12:52 AM | 显示全部楼层
undeclare 表面上看到是因為scope的問題
比如說
void SetDisplayOption(Dictionary * dict)
{
   printf("Set Display Option:\n"
          "1. Show All\n"
          "2. Show Noun\n"
          "3. Show Adjective\n"
          "4. Show Verb");
   
   fgets(string, STR_MAX, stdin);
   dict->displayOption = atoi(string);
}
你的string是在main()宣示的
所以只是local
其他的function是無法access的
回复

使用道具 举报

 楼主| 发表于 10-9-2008 12:58 AM | 显示全部楼层
那要如何改呢??
回复

使用道具 举报

 楼主| 发表于 10-9-2008 02:23 AM | 显示全部楼层

最新的program

#include <stdio.h>
#include <string.h>

typedef struct {
        char word[100];
        char noun[200];
        char adjective[200];
        char verb[200];
} record;

record data[150];

void add(char newWord[100]){
          FILE *fptr;
        fptr=fopen("123.txt","r");
        if (fptr==NULL)
                printf("error in openning file\n");

        fprintf(fptr,"%s",newWord);
        printf("new word has been added\n");
}

void deleted(char reset[100]){
        char blank[100]=" ";
        FILE *fptr;
                fptr=fopen("123.txt","r");
                if (fptr==NULL)
                        printf("error in openning file\n");

                strcpy(reset,blank);
}


       






int main()
{


char word[100];
int menu=0;
char cont;
int choice,y,n,g,i;



record data[150];
       
        FILE *fptr;
        fptr=fopen("123.txt","r");
        if (fptr==NULL)
                printf("error in openning file\n");

        for(i=0; i<100; i++){
        fgets(data.word,100,fptr);
        fgets(data.noun,200,fptr);
        fgets(data.adjective,200,fptr);
        fgets(data.verb,200,fptr);
       
        fclose(fptr);

printf("My dictionary. # of entries : 101. (enter '?' to enter edit mode.)\n");

printf("Search: ");

scanf("%s",word);
do{
  if(word[0]=='?'){
   
     printf("Edit mode:\n");
   
     printf("1. Add word\n");
   
     printf("2. Delete word\n");
   
     printf("3. Set display option\n");
   
     printf("4. Exit display mode\n\n");
   
     printf("Enter your choice: ");
   
     scanf("%d", &choice);


switch (choice) {

        case 1:
                printf("Enter the word you wish to add:\n");
             scanf("%s",word);
             add(word);
        break;
     
        case 2:
                printf("Enter the word you wish to delete: ");
                scanf("%s",word);
                deleted(word);
        break;

        case 3:
        fptr=fopen("123.txt","r");
        printf("1. Show all: All definitions associated with a word will be displayed.\n");
        printf("2. Show noun only: Show only the adjective part of the definition.\n");
        printf("3. Show adjective only: Show only the adjective part of the definition.\n");
        printf("4. Show verb only: Show only the verb of the definition.\n");
        scanf("%d",&y);

        case 4:
        printf("Would you like to exit display mode?\n");
             printf("Enter 'Y' for 'Yes' -- 'N' for 'No':   ");
              scanf("%s",&cont);
       
        default:
                                        printf("\n");
                                        break;

     
  
}

     
      
}
else{
                printf("the word you want to search is %s",word);       
                n=strlen(word);
                for(g=0;g<150;g++){       
                if(strncmp(data[g],word,n)!=0)
                printf("no match found\n");
        else
                printf("%s",data[g]);
        }




   
     fclose(fptr);
   



       
return 0;

}
回复

使用道具 举报

 楼主| 发表于 10-9-2008 02:26 AM | 显示全部楼层
原帖由 callmebrandon 于 10-9-2008 02:23 AM 发表
#include
#include

typedef struct {
        char word[100];
        char noun[200];
        char adjective[200];
        char verb[200];
} record;

record data[150];

void add(char newWord[100]){
          FILE *fptr;
         ...

有一点问题,但是不懂哪里。帮忙一下
还有如何把我的program link 去我的DATABASE???
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-12-2025 11:06 AM , Processed in 0.129252 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表