Ir ao conteúdo

Ajuda em C++


andrewskt

Posts recomendados

Postado

Eae beleza?

então to fazendo um programa pra faculdade que simula evolução de populaçoes

em c++ e to precisando ler os dados de um arquivo e imprimi-los..

Sei que são muitos erros mas se alguem tiver pelo menos alguma solução

da um ajuda aí...

Essa é a ideia do programa:

#include <stdio.h>

#include <stdlib.h>

#define MAXnI 100

#define MAX MAXnI*MAXnI

int main(){

int nI, eil, prl, nL, lobo[MAX][2], ec, prc, nC, coelho[MAX][2], tmax, semente;

Ler(&nI, &eil, &prl, &nL, lobo, &ec, &prc, &nC, coelho, &tmax, &semente);

Imprimir(nI, eil, prl, nL, lobo, ec, prc, nC, coelho, tmax, semente);

void PressioneEnter();

system("pause");

return 0;

}

void Ler(int *nI,

int *eil, int *prl, int *nL, int lobo[MAX][2],

int *ec, int *prc, int *nC, int coelho[MAX][2],

int *tmax,

int *semente){

int lin;

FILE *entrada;

entrada = fopen("entrada.txt","r");

if (entrada == NULL) {

printf("ERRO: arquivo de entrada não encontrado\n");

return -1;

}

fscanf(entrada,"%d",&*nI);

fscanf(entrada,"%d",&*eil);

fscanf(entrada,"%d",&*prl);

fscanf(entrada,"%d",&*nL);

for(lin=0; lin<*nL; lin++){

fscanf(entrada,"%d", &lobo[lin][0]);

fscanf(entrada,"%d", &lobo[lin][1]);

}

fscanf(entrada,"%d",&*ec);

fscanf(entrada,"%d",&*prc);

fscanf(entrada,"%d",&*nC);

for(lin=0, lin<*nC, lin++){

fscanf(entrada,"%d", &coelho[lin][0]);

fscanf(entrada,"%d", &coelho[lin][1]);

}

fscanf(entrada,"%d",&*tmax);

fscanf(entrada,"%d",&*semente);

fclose(entrada);

}

void Imprimir(int n,

int eil, int prl, int nL, int lobo[MAX][2],

int ec, int prc, int nC, int coelho[MAX][2],

int tmax,

int semente){

int i;

printf("Dimensão da ilha = %d\n", n);

printf("Energia inicial dos lobos = &d\n", eil);

printf("Período de reprodução dos lobos = %d\n", prl);

printf("Número de lobos = %d\n", nL);

Printf("Posição dos lobos:\n");

Printf(" linha coluna\n");

for(i=0, i<nL, i++){

printf("%d: ",i);

printf("%d ", lobo[0]);

printf("%d", lobo[1]);

printf("\n");

}

printf("Energia dos coelhos = &d\n", ec);

printf("Período de reprodução dos coelhos = %d\n", prc);

printf("Número de coelhos = %d\n", nC);

Printf("Posição dos coelhos:\n");

Printf(" linha coluna\n");

for(i=0, i<nC, i++){

printf("%d: ",i);

printf("%d ", coelho[0]);

printf("%d", coelho[1]);

printf("\n");

}

printf("Instante máximo da simulação = %d\n", tmax);

printf("Semente = %d\n", semente);

}

void PressioneEnter(){

char ch;

printf("Pressione <enter> para continuar... ");

scanf("%c", &ch);

while (ch != '\n'){

scanf("%c", &ch);

}

}

E os erros que aparecem sao esses:

C:\Documents and Settings\Oliveira\Desktop\teste.c: In function `main':

C:\Documents and Settings\Oliveira\Desktop\teste.c:8: warning: implicit declaration of function `Ler'

C:\Documents and Settings\Oliveira\Desktop\teste.c:10: warning: implicit declaration of function `Imprimir'

C:\Documents and Settings\Oliveira\Desktop\teste.c: At top level:

C:\Documents and Settings\Oliveira\Desktop\teste.c:22: error: conflicting types for 'Ler'

C:\Documents and Settings\Oliveira\Desktop\teste.c:8: error: previous implicit declaration of 'Ler' was here

C:\Documents and Settings\Oliveira\Desktop\teste.c: In function `Ler':

C:\Documents and Settings\Oliveira\Desktop\teste.c:28: warning: `return' with a value, in function returning void

C:\Documents and Settings\Oliveira\Desktop\teste.c:41: warning: left-hand operand of comma expression has no effect

C:\Documents and Settings\Oliveira\Desktop\teste.c:41: error: syntax error before ')' token

C:\Documents and Settings\Oliveira\Desktop\teste.c: At top level:

C:\Documents and Settings\Oliveira\Desktop\teste.c:45: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:45: warning: type defaults to `int' in declaration of `fscanf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:45: error: conflicting types for 'fscanf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:45: note: a parameter list with an ellipsis can't match an empty parameter name list declaration

C:\Documents and Settings\Oliveira\Desktop\teste.c:45: error: conflicting types for 'fscanf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:45: note: a parameter list with an ellipsis can't match an empty parameter name list declaration

C:\Documents and Settings\Oliveira\Desktop\teste.c:45: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:46: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:46: warning: type defaults to `int' in declaration of `fscanf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:46: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:47: warning: type defaults to `int' in declaration of `fclose'

C:\Documents and Settings\Oliveira\Desktop\teste.c:47: warning: parameter names (without types) in function declaration

C:\Documents and Settings\Oliveira\Desktop\teste.c:47: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:48: error: syntax error before '}' token

C:\Documents and Settings\Oliveira\Desktop\teste.c:54: error: conflicting types for 'Imprimir'

C:\Documents and Settings\Oliveira\Desktop\teste.c:10: error: previous implicit declaration of 'Imprimir' was here

C:\Documents and Settings\Oliveira\Desktop\teste.c: In function `Imprimir':

C:\Documents and Settings\Oliveira\Desktop\teste.c:57: warning: too many arguments for format

C:\Documents and Settings\Oliveira\Desktop\teste.c:60: warning: implicit declaration of function `Printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:62: warning: left-hand operand of comma expression has no effect

C:\Documents and Settings\Oliveira\Desktop\teste.c:62: error: syntax error before ')' token

C:\Documents and Settings\Oliveira\Desktop\teste.c: At top level:

C:\Documents and Settings\Oliveira\Desktop\teste.c:68: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:68: warning: type defaults to `int' in declaration of `printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:68: error: conflicting types for 'printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:68: note: a parameter list with an ellipsis can't match an empty parameter name list declaration

C:\Documents and Settings\Oliveira\Desktop\teste.c:68: error: conflicting types for 'printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:68: note: a parameter list with an ellipsis can't match an empty parameter name list declaration

C:\Documents and Settings\Oliveira\Desktop\teste.c:68: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:69: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:69: warning: type defaults to `int' in declaration of `printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:69: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:70: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:70: warning: type defaults to `int' in declaration of `printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:70: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:71: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:71: warning: type defaults to `int' in declaration of `Printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:71: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:72: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:72: warning: type defaults to `int' in declaration of `Printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:72: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:75: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:75: warning: type defaults to `int' in declaration of `printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:75: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:76: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:76: warning: type defaults to `int' in declaration of `printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:76: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:77: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:77: warning: type defaults to `int' in declaration of `printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:77: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:79: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:79: warning: type defaults to `int' in declaration of `printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:79: warning: data definition has no type or storage class

C:\Documents and Settings\Oliveira\Desktop\teste.c:80: error: syntax error before string constant

C:\Documents and Settings\Oliveira\Desktop\teste.c:80: warning: type defaults to `int' in declaration of `printf'

C:\Documents and Settings\Oliveira\Desktop\teste.c:80: warning: data definition has no type or storage class

Execução terminada

Espero a ajuda

Postado

andrewskt, você está programando em C, não em C++. Com relação aos erros, você pode resolver boa parte deles fazendo o seguinte:

- Declarar o cabeçalho das funções auxiliares, ou simplesmente declarar a função main por último;

- Não existe Printf, mas sim printf.

- Na chamada da função PressioneEnter dentro da main, você está colocando um void que não deveria estar lá.

- Na função Ler existe um return -1, mas como a função é do tipo void ela não deve retornar um número, troque para somente return, ou troque o tipo da função pra int e trate esse erro na main;

Espero ter ajudado ;)

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

LANÇAMENTO!

eletronica2025-popup.jpg


CLIQUE AQUI E BAIXE AGORA MESMO!