PDA

Visualizza la versione completa : [C] Errore: parameter... has just a forward declaration


19pino87
19-05-2012, 10:20
Riporto la soluzione, da me scritta, di un esercizio assegnatomi a lezione.


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

#define N 10

int *Crea(void);
void Stampa(int *);
int Min(int *; int);
int MaxC(int *; int *; int);
void f(int *);

int main()
{
int *V = (int *)malloc(sizeof(int)*N);
V = Crea();
Stampa(V);
f(V);
return 0;
}

int *Crea()
{
int i;
int *AUX = (int *)malloc(sizeof(int)*N);
srand((unsigned)time(NULL));
for(i=0; i<N; i++)
AUX[ i] = rand()%25+1;
return AUX;
}

void Stampa(int *X)
{
int i;
for(i=0; i<N; i++)
printf("%d ", X[ i]);
printf("\n");
}

int Min(int *V; int i)
{
int j=0;
while (j<i)
if (V[j] < V[ i])
return 0;
else
j++;
return 1;
}

int MaxC(int *V; int *C; int i)
{
int j;
int maxC = -1;
for(j=0; j<i; j++)
if (V[ i] > V[j])
if (C[j] > maxC)
maxC = C[j];
return maxC;
}

void f(int *V)
{
int i;
int *C = (int *)malloc(sizeof(int)*N);
for(i=0; i<N; i++)
if (i==0)
C[ i] = 1;
else
if (Min(V,i) == 1)
C[ i] = 1;
else
C[ i] = 1+MaxC(V,C,i);
Stampa(C);
}


Concettualmente la soluzione è corretta! Ma il codice riporta i seguenti errori:

gcc -Wall -o "main" "main.c" (nella cartella: /home/peppe/Scrivania/Nuova cartella)
main.c:9:1: error: parameter ‘({anonymous})’ has just a forward declaration
main.c:10:1: error: parameter ‘({anonymous})’ has just a forward declaration
main.c:10:1: error: parameter ‘({anonymous})’ has just a forward declaration
main.c:42:14: error: parameter ‘V’ has just a forward declaration
main.c: In function ‘Min’:
main.c:46:7: error: ‘V’ undeclared (first use in this function)
main.c:46:7: note: each undeclared identifier is reported only once for each function it appears in
main.c: At top level:
main.c:53:23: error: parameter ‘C’ has just a forward declaration
main.c:53:15: error: parameter ‘V’ has just a forward declaration
main.c: In function ‘MaxC’:
main.c:58:7: error: ‘V’ undeclared (first use in this function)
main.c:59:8: error: ‘C’ undeclared (first use in this function)
Compilazione fallita.

Gli errori individuati dal compilatore, a quanto ho capito, sono da ricercare nelle dichiarazioni delle funzioni Min e MaxC...ma non riesco ad individuarli!!

oregon
19-05-2012, 10:23
Come mai non li individui? In

int Min(int *; int);
int MaxC(int *; int *; int);

usi dei ; al posto di , per separare gli argomenti

19pino87
19-05-2012, 10:32
azz...corretti!! :)

Ma la compilazione continua a restituire errori:

gcc -Wall -o "main" "main.c" (nella cartella: /home/peppe/Scrivania/Nuova cartella)
main.c:42:14: error: parameter ‘V’ has just a forward declaration
main.c:42:5: error: conflicting types for ‘Min’
main.c:9:5: note: previous declaration of ‘Min’ was here
main.c: In function ‘Min’:
main.c:46:7: error: ‘V’ undeclared (first use in this function)
main.c:46:7: note: each undeclared identifier is reported only once for each function it appears in
main.c: At top level:
main.c:53:23: error: parameter ‘C’ has just a forward declaration
main.c:53:15: error: parameter ‘V’ has just a forward declaration
main.c:53:5: error: conflicting types for ‘MaxC’
main.c:10:5: note: previous declaration of ‘MaxC’ was here
main.c: In function ‘MaxC’:
main.c:58:7: error: ‘V’ undeclared (first use in this function)
main.c:59:8: error: ‘C’ undeclared (first use in this function)
main.c: In function ‘f’:
main.c:72:4: warning: passing argument 1 of ‘Min’ makes integer from pointer without a cast [enabled by default]
main.c:42:5: note: expected ‘int’ but argument is of type ‘int *’
main.c:72:4: error: too many arguments to function ‘Min’
main.c:42:5: note: declared here
main.c:75:5: warning: passing argument 1 of ‘MaxC’ makes integer from pointer without a cast [enabled by default]
main.c:53:5: note: expected ‘int’ but argument is of type ‘int *’
main.c:75:5: error: too many arguments to function ‘MaxC’
main.c:53:5: note: declared here
Compilazione fallita.

19pino87
19-05-2012, 10:33
Risolto!!!!! Troppo distratto!!!
Grazie mille!!!! :)

alka
21-05-2012, 15:31
Originariamente inviato da 19pino87
[C] Problema esercizio

In futuro, invito a usare titoli più significativi e rappresentativi del contenuto della discussione, come richiesto dal Regolamento (http://forum.html.it/forum/showthread.php?s=&threadid=973887), e non così generici e astratti.

Qui ho corretto io.

Loading