Salve a tutti,
non riesco a capire come mai questo programma non compila.
Questo è il risultato della compilazione sulla piattaforma CMS:
studioamico.cpp: In function ‘int main()’:
studioamico.cpp:43:29: warning: ignoring return value of ‘int fscanf(FILE*, const char*, …)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(fr, “%d”, &N);
^
studioamico.cpp:47:41: warning: ignoring return value of ‘int fscanf(FILE*, const char*, …)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(fr, “%d”, &voti2[i0]);
^
studioamico.cpp:51:41: warning: ignoring return value of ‘int fscanf(FILE*, const char*, …)’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(fr, “%d”, &voti5[i0]);
^
/tmp/ccSe1gEm.o: In function main': studioamico.cpp:(.text.startup+0x0): multiple definition of
main’
/tmp/cc41OdcL.o:grader.cpp:(.text.startup+0x0): first defined here
Questo è il codice del programma
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
static FILE *fr, *fw;
static int N;
static int* voti2;
static int* voti5;
static int res;
int i,insospeso,studentiassociati;
int studenti5[11];
int studenti2[11];
bool associabili(int N, int* voti2, int* voti5)
{
if(studenti2[10]!=0 || studenti5[0]!=0)
return false;
i=10;
while (i>=1)
{
if (studenti5[i]-studenti2[i-1]<0 && insospeso<studenti5[i]-studenti2[i-1])
return false;
if (studenti5[i]-studenti2[i-1]<0 && insospeso>=studenti5[i]-studenti2[i-1])
insospeso-=studenti5[i]-studenti2[i-1];
if (studenti5[i]-studenti2[i-1]>=0)
insospeso+=studenti5[i]-studenti2[i-1];
i–;
}
return true;
}
int main() {
fr = stdin;
fw = stdout;
int i0;
fscanf(fr, "%d", &N);
voti2 = (int*)malloc(N * sizeof(int));
voti5 = (int*)malloc(N * sizeof(int));
for (i0 = 0; i0 < N; i0++) {
fscanf(fr, "%d", &voti2[i0]);
studenti2[voti2[i0]]++;
}
for (i0 = 0; i0 < N; i0++) {
fscanf(fr, "%d", &voti5[i0]);
studenti5[voti5[i0]]++;
}
res = associabili(N, voti2, voti5);
fprintf(fw, "%d\n", res);
fclose(fr);
fclose(fw);
return 0;
}
collect2: error: ld returned 1 exit statusTesto preformattato