2014-05-20 2 views
0

안녕하세요 내 문제는 다음과 같은 내 프로젝트를 컴파일하고 싶지 않아 그것은 내 기능 중 일부는 범위에서 선언되지 않았다는 말은 작동하지만 그들은 왜 나던 컴파일 왜 이해가 안 돼범위 오류 함수가 선언되지 않았습니다

내 코드 :

헤더 파일 :

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

typedef struct s { 
int id; 
int tipo_sorte; 
char descricao[100]; 
int consequencia; 
} S; 

typedef struct sorte{ 
S s; 
struct sorte *anterior; 
struct sorte *proximo; 
}SORTE; 

typedef struct t { 
int id; 
int n_casa; 
} T; 

typedef struct tabuleiro{ 
T t; 
struct tabuleiro *anterior; 
struct tabuleiro *proximo; 
}TABULEIRO; 

typedef struct j { 
int id; 
char nome[50]; 
char sigla[5]; 
int jogadas; 
} J; 

typedef struct jogador{ 
J j; 
struct jogador *anterior; 
struct jogador *proximo; 
}JOGADOR; 

주요 파일 :

#include "lista.h" 

int main() 
{ 
int opcao=0, a = 0; 
SORTE *inicio = NULL; 
JOGADOR *ini = NULL; 
TABULEIRO *tini = NULL; 
SORTE *fim = NULL; 
TABULEIRO *tfim = NULL; 
JOGADOR *end = NULL; 


printf(" ----------------------------------------------------------------------------\n" 
     "|        Monopolio 2014.        |\n" 
     "|         Bem-Vindo.        |\n" 
     " ----------------------------------------------------------------------------\n"); 

    //carregaPerguntas(&inicio, &fim); 
    //carregaJogadores(&ini, &end); 
    // system("PAUSE"); 




    do{ 
    system("cls"); 
    printf(" -----------------------------------------------------------------------------\n"); 
    printf("| 1 - Jogar                 |\n"); 
    printf("| 2 - Administrador               |\n"); 
    printf("| 3 - Recordes TOP 10               |\n"); 
    printf("| 4 - Sair                 |\n"); 
    printf(" -----------------------------------------------------------------------------\n\n->"); 
    fflush(stdin); 
    scanf("%d",&opcao); 
    switch(opcao) { 
     case 1 : system("cls"); 
//     jogar(inicio,fim, &ini, &end); 

        break; 
     case 2 : system("cls"); 
        a = validaLogin(); 
        if(a==0){ 
         menuAdmin(); 

        } 
        if(a==1){ 

         menuAdmin1(&inicio, &fim); 
        }else{ 
         //menuAdmin2(&inicio, &fim); 
        } 
        break; 
     case 3 : system("cls"); 
    //     carregaRecordes(&ini, &end); 
    //    listaRecordes(ini); 
        break; 

     case 4 : system("cls"); 
        printf(" -----------------------------------------------------------------------------\n"); 
        printf("| Obrigado por ter jogado.             |\n"); 
        printf(" -----------------------------------------------------------------------------\n"); 
        system("PAUSE"); 
     default : if(opcao<1 || opcao>4) { 
        system("cls"); 
        printf("Opcao Invalida.\n"); 
        system("PAUSE"); 

        } 
        break; 
    } 
}while(opcao!=4); 
// gravaRecordes(ini); 
system("cls"); 
return 0; 
} 

관리자 파일 :

#include "lista.h" 

int validaLogin(){ 
system("cls"); 
char pass[20]="", passwd[20]=""; 
int n_tenta = 3; 
FILE *fp = fopen("pass.dat","r+b"); 
if(fp==NULL){ 
    printf("Primeiro Acesso. Por favor defina a password.\n"); 
    fflush(stdin); 
    gets(pass); 
    fclose(fp); 
    fp=fopen("pass.dat","wb"); 
    fwrite(pass,sizeof(pass),1,fp); 
    printf("\n\nPassword definida com sucesso.\n"); 
    system("PAUSE"); 
    fclose(fp); 
    return 0; 
} 
    do{ 
    fflush(stdin); 
    fread(passwd,sizeof(passwd),1,fp); 
    printf("Introduza a password de acesso ao modo de administracao.\n"); 
    fflush(stdin); 
    gets(pass); 
    if(strcmp(pass,passwd)!=0){ 
     system("cls"); 
     n_tenta--; 
     printf("Password invalida. Restam %d tentativas.\n",n_tenta); 
     if(n_tenta==0){ 
      printf("A sair do modo de administracao.\n"); 
      system("PAUSE"); 
      return -1; 
     } 
    } 
    else{ 
     printf("Password inserida com sucesso.\n"); 
     system("pause"); 
    } 
}while(strcmp(pass,passwd)!=0); 
fclose(fp); 
return 0; 
} 



void inserePergunta(SORTE **inicio, SORTE **fim){ 
SORTE *novo = (SORTE*) malloc(sizeof(SORTE); 
int gr=0, a=0; 
if(novo==NULL){ 
    system("cls"); 
    printf("Erro na reserva de memoria.\n"); 
    system("pause"); 
    return; 
} 
printf(" -----------------------------------------------------------------------------\n"); 
printf("| Insira o tipo de consequencia da carta da sorta       |\n"); 
printf(" -----------------------------------------------------------------------------\n"); 
printf("| 1 - Recuar                 |\n"); 
printf("| 2 - Avancar                |\n"); 
printf("| 3 - Saltar                 |\n"); 
printf(" -----------------------------------------------------------------------------\n->"); 
do{ 
    fflush(stdin); 
    scanf("%d",&gr); 
    if(gr<1 || gr>3){ 
     printf("Opcao errada.\nInsira novamente.\n->"); 
    } 
}while(gr<1 || gr>3); 
novo->s.tipo_sorte = gr; 
system("cls"); 
printf("Insira o tipo da consequencia.\n->"); 
fflush(stdin); 
gets(novo->s.descricao); 
if(gr==1 || gr==2 || gr==3){ 
    printf("Insira o numero de casas.\n->"); 
      fflush(stdin); 
      scanf("%d",&novo->s.consequencia); 

} 
if(*inicio==NULL){ 
    novo->s.id=1; 
} 
else{ 
    novo->s.id = (*fim)->s.id + 1; 
} 
inserirListaP(novo->s, &(*inicio), &(*fim)); 
printf("ID da casa - %d\n",novo->s.id); 
system("pause"); 
} 

int listaPerguntas(SORTE *inicio){ 
SORTE *auxi = inicio; 
char group[50]=""; 
if(auxi==NULL){ 
    return -1; 
} 
while(auxi!=NULL){ 
    if(auxi->s.tipo_sorte==1){ 
     strcpy(group,"Recuar"); 
    } 
    if(auxi->s.tipo_sorte==2){ 
     strcpy(group,"Avancar"); 
    } 
    if(auxi->s.tipo_sorte==3){ 
     strcpy(group,"Saltar"); 
    } 
    printf(" -----------------------------------------------------------------------------\n"); 
    printf("| ID: %d\n",auxi->s.id); 
    printf("| Carta:\t%s\n",auxi->s.descricao); 
    printf("| Tipo Carta: %d (%s)\n",auxi->s.tipo_sorte,group); 
    printf("| Consequencia: %d\n",auxi->s.consequencia); 
    printf(" -----------------------------------------------------------------------------\n\n"); 
    auxi = auxi->proximo; 
} 
return 1; 
} 

void editaPergunta(SORTE *inicio){ 
system("cls"); 
SORTE *aux = inicio; 
int auxi=0, l=0, a=0; 
l = listaPerguntas(inicio); 
if(l==-1){ 
      printf(" -----------------------------------------------------------------------------\n"); 
    printf("| Nao existem cartas inseridas para poder alterar.\n"); 
    printf(" -----------------------------------------------------------------------------\n"); 
    system("pause"); 
    return; 
} 
printf(" -----------------------------------------------------------------------------\n"); 
printf("| Insira o id da carta a alterar.\n"); 
printf(" -----------------------------------------------------------------------------\n->"); 
fflush(stdin); 
scanf("%d",&auxi); 
while(aux!=NULL){ 
    if(aux->s.id == auxi) { 
     printf("Edite a carta.\n->"); 
     fflush(stdin); 
     gets(aux->s.descricao); 
     printf("Introduza nova consequencia.\n->"); 
     fflush(stdin); 
     scanf("%d",&aux->s.consequencia); 
     } 
     printf(" -----------------------------------------------------------------------------\n"); 
     printf("| Dados editados com sucesso.\n"); 
     printf(" -----------------------------------------------------------------------------\n"); 
     system("pause"); 
     return; 
    } 
    else { 
     aux = aux->proximo; 
    } 
} 
printf(" -----------------------------------------------------------------------------\n"); 
printf("| A carta com o id '%d' nao existe.\n",auxi); 
printf(" -----------------------------------------------------------------------------\n"); 
system("pause"); 
} 

void eliminaPergunta(SORTE **inicio, SORTE **fim){ 
SORTE *aux = *inicio; 
int l=0, i=0; 
l = listaPerguntas(*inicio); 
if(l==-1){ 
    printf(" -----------------------------------------------------------------------------\n"); 
    printf("| Nao existem cartas inseridas para poder eliminar.\n"); 
    printf(" -----------------------------------------------------------------------------\n"); 
    system("pause"); 
    return; 
} 
printf(" -----------------------------------------------------------------------------\n"); 
printf("| Insira o id da carta a eliminar.\n->"); 
printf(" -----------------------------------------------------------------------------\n"); 
fflush(stdin); 
scanf("%d",&i); 
while(aux!=NULL && aux->s.id != i) { 
    aux = aux->proximo; 
} 
if(aux==NULL){ 
    printf(" -----------------------------------------------------------------------------\n"); 
    printf("| A carta com o id '%d' nao existe.\n",i); 
    printf(" -----------------------------------------------------------------------------\n"); 
    system("pause"); 
    return; 
} 
if(aux->anterior==NULL) { 
    *inicio = aux->proximo; 
    if(*inicio) (*inicio)->anterior = NULL; 
} 
else 
    aux->anterior->proximo = aux->proximo; 
    if(aux->proximo==NULL) { 
     *fim = aux->anterior; 
     if(*fim) (*fim)->proximo=NULL; 
    } 
    else 
    aux->proximo->anterior = aux->anterior; 
    free(aux); 
    printf(" -----------------------------------------------------------------------------\n"); 
    printf("| Carta removida.\n"); 
    printf(" -----------------------------------------------------------------------------\n"); 
    system("pause"); 
} 

void menuAdmin(){ 
system("cls"); 


    system("cls"); 
    printf(" -----------------------------------------------------------------------------\n"); 
    printf("|     Menu Administracao.          |\n"); 
    printf(" -----------------------------------------------------------------------------\n"); 
    printf("| 1 - Gerir Cartas da sorte             |\n"); 
    printf("| 2 - Gerir Tabuleiro               |\n"); 
    printf("| 0 - Menu anterior               |\n"); 
    printf(" -----------------------------------------------------------------------------\n->"); 

} 


void menuAdmin1(SORTE **inicio, SORTE **fim){ 
system("cls"); 
int op=0; 
do{ 
    system("cls"); 
    printf(" -----------------------------------------------------------------------------\n"); 
    printf("|     Menu Administracao.          |\n"); 
    printf(" -----------------------------------------------------------------------------\n"); 
    printf("| 1 - Inserir Pergunta              |\n"); 
    printf("| 2 - Editar Pergunta               |\n"); 
    printf("| 3 - Eliminar pergunta              |\n"); 
    printf("| 0 - Menu anterior               |\n"); 
    printf(" -----------------------------------------------------------------------------\n->"); 
    fflush(stdin); 
    scanf("%d",&op); 
    switch(op){ 
     case 1: system("cls"); 
       inserePergunta(&(*inicio), &(*fim)); 
       break; 
     case 2: system("cls"); 
       editaPergunta(*inicio); 
       break; 
     case 3: system("cls"); 
       eliminaPergunta(&(*inicio), &(*fim)); 
       break; 
     default:if(op<0 || op>3){ 
        printf("Opcao errada.\n"); 
        system("PAUSE"); 
       } 
       gravaPerguntas(*inicio); 
       system("PAUSE"); 
       break; 
    } 
}while(op!=0); 
} 

오류 로그 :

C:\Users\JD\Desktop\Prog\main.c In function 'int main()': 
42 41 C:\Users\JD\Desktop\Prog\main.c [Error] 'validaLogin' was not declared in this scope 
44 38 C:\Users\JD\Desktop\Prog\main.c [Error] 'menuAdmin' was not declared in this scope 
49 35 C:\Users\JD\Desktop\Prog\main.c [Error] 'menuAdmin1' was not declared in this scope 
28  C:\Users\JD\Desktop\Prog\Makefile.win recipe for target 'main.o' failed 

이러한 기능

난이 오류가 나에게 문의하기 전에 함수를 선언 할 필요

답변

0

도와주세요 이유를 이해 해달라고 관리 파일에 있습니다 그 (것)들은, 시제품 유형를 추가해서.

예를 들어, main.cpp 파일의 경우 main 함수 앞에 예를 들어를 입력합니다. 함수 선언이며, validaLogin의 이름을 가진 함수가 인수를 취하지 않는 것을 존재하는 컴파일러를 알려줍니다과는 int을 반환하는 다음 줄

int validaLogin(); 

.


는 명확하게, 당신의 main.cpp 파일뿐만 아니라 다른 기능을 추가 할 필요가 당신 물론

#include "lista.h" 

// Declare function prototypes of the functions I use, 
// but are defined in another file 
int validaLogin(); 

int main() 
{ 
    // All your code here 
} 

과 같아야합니다 확인하십시오.

+0

나는 do 함수 안에있는 메인에서 이것을한다. – user3626801

+0

@ user3626801 'main' 함수 안에서 함수를 호출하지만 아무 것도 * 선언하지 않는다. 적어도 당신이 당신의 질문에 가지고있는 코드에는 없습니다. –

+0

나는 관리자 파일에 valialogin 함수를 가지고 있는데, mai에서는 int a를 선언한다; 및 경우 2 : a = validalogin(); – user3626801

0

.h 파일에는 함수 및 형식 선언의 전달 선언 만 있어야하며 .cpp 파일에는 함수 본문 만 있어야합니다. .cpp 파일에서 함수를 사용하는 경우 해당 함수가 들어있는 .h 파일의 포함을 추가해야합니다.

관련 문제