PDA

Visualizza Versione Completa : Non compila piu' in C?!?



iGodness
23-03-07, 17:01
Tempo fa avevo installato XCode per compilare da terminale in C.

Ultimamente pero', non riesco piu' a compilare. La stringa di comando e' sempre la stessa:

gcc -o fileout DataParole.c

Ma niente... Mi da sempre errore.
Ho pensato "Forse sono i nuovi sorgenti che non sono corretti". Allora provo con quelli di un tempo -che funzionavano- ma anche con quelli... niente da fare.

Forse sono un filo stressato ultimamente e canno qualcosa.. Sapreste dirmi soluzioni in merito?

TheCube
23-03-07, 17:19
Potresti fare almeno lo sforzo di riportare l'errore segnalato dal compilatore, o ritieni che si sia dotati di poteri paranormali?

iGodness
23-03-07, 17:26
:roll: Perdono.

Eccoti accontentato. Direttamente dal terminale:

DataParole.c: In function 'caso':
DataParole.c:182: error: missing terminating " character
DataParole.c:183: error: 'contrario' undeclared (first use in this function)
DataParole.c:183: error: (Each undeclared identifier is reported only once
DataParole.c:183: error: for each function it appears in.)
DataParole.c:183: error: stray '\' in program
DataParole.c:183: error: stray '\' in program
DataParole.c:183: error: parse error before 'n'
DataParole.c:183: error: missing terminating " character
DataParole.c: At top level:
DataParole.c:196: error: parse error before 'while'
DataParole.c:199: error: missing terminating " character
DataParole.c:200: error: missing terminating " character
DataParole.c:202: error: conflicting types for 'pulisci'
DataParole.c:35: error: previous declaration of 'pulisci' was here
DataParole.c:202: warning: data definition has no type or storage class
DataParole.c:203: error: parse error before 'return'
DataParole.c:206: error: missing terminating " character
DataParole.c:207: error: parse error before '.' token
DataParole.c:207: error: stray '\' in program
DataParole.c:207: error: stray '\' in program
DataParole.c:207: error: missing terminating " character
DataParole.c:217: warning: data definition has no type or storage class
DataParole.c:219: error: parse error before 'if'
DataParole.c:222: error: redefinition of 'control_flag'
DataParole.c:217: error: previous definition of 'control_flag' was here
DataParole.c:222: warning: data definition has no type or storage class
DataParole.c:223: error: parse error before '}' token
DataParole.c:227: error: missing terminating " character
DataParole.c:228: error: missing terminating " character
DataParole.c:233: error: 's' undeclared here (not in a function)
DataParole.c:233: warning: data definition has no type or storage class
DataParole.c:234: error: parse error before 'for'
DataParole.c:239: error: conflicting types for 'pulisci'
DataParole.c:35: error: previous declaration of 'pulisci' was here
DataParole.c:239: warning: data definition has no type or storage class
DataParole.c:240: error: parse error before 'return'
DataParole.c:250: error: 'rem2' undeclared here (not in a function)
DataParole.c:250: error: parse error before '.' token
DataParole.c:252: error: parse error before string constant
DataParole.c:252: error: conflicting types for 'printf'
DataParole.c:252: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
DataParole.c:252: warning: data definition has no type or storage class
DataParole.c:257: warning: parameter names (without types) in function declaration
DataParole.c:257: error: conflicting types for 'gets'
/usr/include/stdio.h:271: error: previous declaration of 'gets' was here
DataParole.c:257: warning: data definition has no type or storage class
DataParole.c:258: error: parse error before '++' token
DataParole.c:263: warning: data definition has no type or storage class
DataParole.c:264: error: parse error before 'for'
DataParole.c:269: error: conflicting types for 'pulisci'
DataParole.c:35: error: previous declaration of 'pulisci' was here
DataParole.c:269: warning: data definition has no type or storage class
DataParole.c:270: error: parse error before 'return'
DataParole.c: In function 'save':
DataParole.c:327: error: missing terminating " character
DataParole.c:328: error: 'sul' undeclared (first use in this function)
DataParole.c:328: error: parse error before 'file'
DataParole.c:328: error: stray '\' in program
DataParole.c:328: error: missing terminating " character
DataParole.c:329: error: missing terminating " character
DataParole.c:330: error: stray '\' in program
DataParole.c:330: error: missing terminating " character
DataParole.c: In function 'load_file':
DataParole.c:354: error: missing terminating " character
DataParole.c:355: error: 'y' undeclared (first use in this function)
DataParole.c:355: error: 'n' undeclared (first use in this function)
DataParole.c:355: error: stray '\' in program
DataParole.c:355: error: missing terminating " character
DataParole.c:357: error: parse error before 'do'
DataParole.c: At top level:
DataParole.c:360: error: parse error before 'while'
DataParole.c:362: error: parse error before string constant
DataParole.c:362: error: conflicting types for 'printf'
DataParole.c:362: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
DataParole.c:362: warning: data definition has no type or storage class
DataParole.c:367: error: missing terminating " character
DataParole.c:368: error: missing terminating " character
DataParole.c:370: error: parse error before string constant
DataParole.c:370: error: conflicting types for 'printf'
DataParole.c:370: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
DataParole.c:370: warning: data definition has no type or storage class
DataParole.c:371: warning: parameter names (without types) in function declaration
DataParole.c:371: error: conflicting types for 'gets'
/usr/include/stdio.h:271: error: previous declaration of 'gets' was here
DataParole.c:371: warning: data definition has no type or storage class
DataParole.c:373: warning: parameter names (without types) in function declaration
DataParole.c:373: error: conflicting types for 'strcat'
DataParole.c:373: warning: data definition has no type or storage class
DataParole.c:374: warning: parameter names (without types) in function declaration
DataParole.c:374: error: conflicting types for 'strcat'
DataParole.c:374: warning: data definition has no type or storage class
DataParole.c:376: warning: data definition has no type or storage class
DataParole.c:378: error: parse error before 'if'
DataParole.c:380: error: redefinition of 'ok'
DataParole.c:376: error: previous definition of 'ok' was here
DataParole.c:380: warning: data definition has no type or storage class
DataParole.c:381: error: parse error before '}' token
DataParole.c:397: error: 't' undeclared here (not in a function)
DataParole.c:397: error: parse error before '++' token
DataParole.c:398: error: 'i' undeclared here (not in a function)
DataParole.c:398: error: initializer element is not constant
DataParole.c:398: warning: data definition has no type or storage class
DataParole.c:399: error: parse error before 'if'
DataParole.c:402: warning: parameter names (without types) in function declaration
DataParole.c:402: warning: data definition has no type or storage class
DataParole.c:403: error: parse error before '}' token
DataParole.c:408: error: conflicting types for 'svuota'
DataParole.c:36: error: previous declaration of 'svuota' was here
DataParole.c:408: warning: data definition has no type or storage class
DataParole.c:409: error: parse error before string constant
DataParole.c:409: error: conflicting types for 'strcat'
DataParole.c:409: warning: data definition has no type or storage class
DataParole.c:410: error: conflicting types for 'pulisci'
DataParole.c:35: error: previous declaration of 'pulisci' was here
DataParole.c:410: warning: data definition has no type or storage class
DataParole.c:411: error: parse error before 'break'




/**********************************Librerie
usate********************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

/******************************Definizione
costanti******************************/
#define MPAROLE 501
#define MSLOT 6
#define DIM 51
#define offset 3

/*********************************Strutture
usete********************************/
typedef struct{
char nome[DIM];
int flag;
}dataparole;

typedef struct{
dataparole parole[MPAROLE];
int flag;
}dataslot;

/********************************Variabili
globali*******************************/
dataslot slot[MSLOT];
int ord_ok=0,cont_temp_records[MSLOT],cont_records[MSLOT],m_len=0;
char *ext=".ceby",Percorso[50];

/******************************Prototipi di
funzioni*****************************/
void init_list(void), load_file(void);
void add(void), pulisci(void), load_new(void);
void view(void), caso(void), svuota(void);
void help(void), save(int e), statistiche(void);
int menu_select(void);
int find_free(int num_slot);

/*******************************Funzione
principale******************************/
int main(void){
int choice;

pulisci();
init_list();
load_file();

for(;;){
choice=menu_select();
switch(choice){
case 1: add();
break;
case 2: view();
break;
case 3: caso();
break;
case 4: load_new();
break;
case 5: statistiche();
break;
case 6: save(0);
break;
case 7: help();
break;
case 8: save(1);
break;
}
}
return 0;
}

/*****************************Inizializza la
struttura***************************/
void init_list(void){
register int t,g,x;
for(t=0; t<MSLOT; t++){
cont_temp_records[t]=0;
cont_records[t]=0;
slot[t].flag=0;
for(g=0; g<MPAROLE; g++){
slot[t].parole[g].flag=0;
for(x=0; x<DIM; x++){
slot[t].parole[g].nome[x]='\0';
}
}
}
}

/**************************Creazione e selezione del
menu************************/
int menu_select(void){
char ch[2];
int num;
printf("\n\t\tRANDOMIZZATORE DI PAROLE CON DATABASE\n\n");
printf(" Nome file corrente: %s\n\n", Percorso);
printf(" 1) Inserisci le parole\n");
printf(" 2) Visualizza o modifica le parole\n");
printf(" 3) Randomizzatore\n");
printf(" 4) Carica un nuovo database\n");
printf(" 5) Statistiche\n");
printf(" 6) Salva\n");
printf(" 7) Guida\n");
printf(" 8) Esci\n\n");

do{
printf(" Immetti la scelta: ");
gets(ch);
num=atoi(ch);
}while(num<1 || num>8);

printf("\n");
return num;
}

/**************************Trova il primo record
vuoto***************************/
int find_free(int num_slot){
register int g;
for(g=0; slot[num_slot].parole[g].nome[0] && g<MPAROLE; g++)
if(g==MPAROLE) return -1; /* tutte le strutture sono occupate */
return g;
}

/***********************Inserimento dati nella
struttura*************************/
void add(){
char ch[2];
int num,pos_free,control=0,len=0;

ord_ok=0;

printf(" Hai a disposizione %d database indipendenti.\n", MSLOT);

do{
printf(" Scegline uno da 0 a %d compresi: ", MSLOT-1);
gets(ch);
num=atoi(ch);
if(num==0 && ch[0]!='0') num=MSLOT;
}while(num<0 || num>MSLOT-1);

pos_free=find_free(num);

if(pos_free==-1){
printf("\n\n Elenco completo\n\n\n");
printf("\tPremi un tasto per continuare...");
getchar();
pulisci();
return;
}

printf("\n\n");
printf(" Ti trovi nel database numero %d\n", num);

do{
printf(" Posizione numero %d, immettere il nome: ", pos_free);
gets(slot[num].parole[pos_free].nome);
if(slot[num].parole[pos_free].nome[0]=='\0') control=0;
else{
control=1;
cont_records[num]++;
len=strlen(slot[num].parole[pos_free].nome);
if(len>m_len) m_len=strlen(slot[num].parole[pos_free].nome);
pos_free=find_free(num);
}
}while(control);

pulisci();
return;
}

/*******************************Randomizzatore***** ******************************/
void caso(void){
char ch[2],esc[2];
int rem1=0,rem2=0,i=0,data[MSLOT];
int esci=0,control_flag=0,cont_slot=0;
register int s,u;

pulisci();

printf("\n Inserisci 1 nei database da randomizzare, 0 in caso
contrario.\n\n");

do{
printf(" Database numero %d: ",i);
gets(ch);
data[i]=atoi(ch);
if(data[i]==1){
i++;
cont_slot++;
}else if(data[i]==0 && ch[0]=='0'){
i++;
esci++;
}
}while(i<MSLOT);

if(esci==MSLOT){
printf("\n\n Non hai selezionato nessun database, premi invio per tornare
al menu...");
getchar();
pulisci();
return;
}

printf("\n Premi invio per continuare, il tasto 'q' per tornare al
menu.\n\n");
i=0;

do{
do{
rem2=rand()%MSLOT;
}while(!(data[rem2]) || slot[rem2].flag==1);

do{
rem1=rand()%MPAROLE;
control_flag=1;

if(slot[rem2].parole[rem1].nome[0]!='\0' &&
slot[rem2].parole[rem1].flag==0){
cont_temp_records[rem2]++;
control_flag=0;
}else if(cont_temp_records[rem2]==cont_records[rem2]){
slot[rem2].flag=1;
cont_slot--;
if(cont_slot==0){
printf(" Sono stati inseriti tutti i records, premi invio per
uscire...");
getchar();

for(s=0; s<MSLOT; s++){
slot[s].flag=0;
cont_temp_records[s]=0;
for(u=0; u<MPAROLE; u++){
slot[s].parole[u].flag=0;
}
}

pulisci();
return;
}else if(cont_slot>0){
do{
rem2=rand()%MSLOT;
}while(!(data[rem2]) || slot[rem2].flag==1);
}
}

}while(control_flag);

slot[rem2].parole[rem1].flag=1;

printf(" %d) parola: %s\n", i,slot[rem2].parole[rem1].nome);

//controllo
//printf(" pos:%d slot:%d\n", rem1,rem2);

gets(esc);
i++;
}while(esc[0]!='q');

for(s=0; s<MSLOT; s++){
slot[s].flag=0;
cont_temp_records[s]=0;
for(u=0; u<MPAROLE; u++){
slot[s].parole[u].flag=0;
}
}

pulisci();
return;
}

/****************************Help ed info sul
programma**************************/
void help(void)
{
pulisci();
printf("\n\n Nome programma: RANDOMIZZATORE DI PAROLE CON DATABASE\n");
printf(" Versione: 1.0\n");
printf(" Piattaforma: sorgente per Mac/Linux/Win\n");
printf(" Data prima versione: 14/01/07\n");
printf(" Data ultima versione: 24/01/07\n");
printf(" Realizzato da Cebycev ofFire\n");
printf(" Mail: acul_amd@hotmail.it\n");
printf(" Descrizione: \n\n\n");

printf("\n\n\n Premi un tasto per continuare...");
getchar();
pulisci();
return;
}

/**********************Salvare la struttura su file ed
uscire********************/
void save(int e){
FILE *fp;
char NomeFile[50];
int i,t,ok=0;

pulisci();

printf("\n\t\tRANDOMIZZATORE DI PAROLE CON DATABASE\n\n");

do{
if(Percorso[0]=='>'){
printf(" Inserisci il percorso del file da salvare: ");
gets(Percorso);
printf(" Inserisci il nome del file senza esensione: ");
gets(NomeFile);
strcat(Percorso,NomeFile);
strcat(Percorso,ext);
}

ok=0;

if((fp=fopen(Percorso, "wb"))==NULL){
printf("\n Impossibile salvare il file.\n\n");
ok=1;
}
}while(ok);

pulisci();

for(t=0; t<MSLOT; t++){
for(i=0; i<MPAROLE; i++){
if(slot[t].parole[i].nome[0]!='\0'){
if(fwrite(&t, sizeof(int), 1, fp)!=1) printf("\n Errore di scrittura
sul file.\n");
if(fwrite(&i, sizeof(int), 1, fp)!=1) printf("\n Errore di scrittura
sul file.\n");
if(fwrite(slot[t].parole[i].nome, sizeof(char)*DIM-1, 1, fp)!=1)
printf("\n Errore di scrittura sul file.\n");
}
}
}

fclose(fp);

if(e) exit(0);
else return;
}


/***********************Caricare i dati dal file alla
struttura******************/
void load_file(void){
FILE *fp;
char NomeFile[50],ch[2];
int i,t,ok=0,len=0;

pulisci();

printf("\n\t\tRANDOMIZZATORE DI PAROLE CON DATABASE\n\n");
printf(" Cosa vuoi fare, vuoi caricare un database gia' esistente
(y/n)?\n");

do{
printf(" Immetti la scelta: ");
gets(ch);
}while(ch[0]!='y' && ch[0]!='n');

printf("\n");

switch(ch[0]){
case 'y':
do{
printf("\n Inserisci il percorso del file da caricare (vuoto, cartella
corrente): ");
gets(Percorso);
printf(" Inserisci il nome del file senza esensione: ");
gets(NomeFile);

strcat(Percorso,NomeFile);
strcat(Percorso,ext);

ok=0;

if((fp=fopen(Percorso, "rb"))==NULL){
printf("\n Impossibile aprire il file.\n\n");
ok=1;
}else{
pulisci();

while(!feof(fp)){
if(fread(&t, sizeof(int), 1, fp)!=1){
if(feof(fp)) break;/* esegue break raggiunta la fine del file */
else printf("\n Errore di lettura del file.\n");
}
if(fread(&i, sizeof(int), 1, fp)!=1){
if(feof(fp)) break;/* esegue break raggiunta la fine del file */
else printf("\n Errore di lettura del file.\n");
}
if(fread(slot[t].parole[i].nome, sizeof(char)*DIM-1, 1, fp)!=1){
if(feof(fp)) break;/* esegue break raggiunta la fine del file */
else printf("\n Errore di lettura del file.\n");
}
cont_records[t]++;
len=strlen(slot[t].parole[i].nome);
if(len>m_len) m_len=strlen(slot[t].parole[i].nome);
}

fclose(fp);
}
}while(ok);
break;
case 'n':
printf("\n Nessun file caricato\n\n");
svuota();
strcat(Percorso,">Nessun file caricato");
pulisci();
break;
}
return;
}

/**************************Funzione che svuota l'array
Percorso*****************/
void svuota(){
register int y;
int len;
len=strlen(Percorso);
for(y=0; y<len; y++) Percorso[y]='\0';
return;
}

/************Funzione per caricare un nuovo database, prima salva il
vecchio*****/
void load_new(){
save(0);
load_file();
pulisci();
return;
}

/*************************************Statistiche** ******************************/
void statistiche(void){
register int i;

pulisci();

printf("\n\t\tRANDOMIZZATORE DI PAROLE CON DATABASE\n\n");
printf(" PAROLE:\n");
printf(" La parola piu' lunga che posso inserire: %d (char)\n", DIM);
printf(" La parola piu' lunga inserita: %d (char)\n\n", m_len);

printf(" DATABASE:\n");
for(i=0; i<MSLOT; i++) printf(" Il database %d contiene: %d (parole)\n",
i,cont_records[i]);

printf("\n\n\n Premi un tasto per continuare...");
getchar();
pulisci();
return;
}

/******************************Visualizza la
struttura***************************/
void view(void){
char ch[2];
int num_data,num_rec,num_rec2,num,num3=0,len=0;
register int i,t,r,p;

pulisci();

do{
printf("\n Inserisci il numero di database da visualizzare: ");
gets(ch);
num_data=atoi(ch);
if(num_data==0 && ch[0]!='0') num_data=MSLOT;
}while(num_data<0 || num_data>MSLOT-1);

printf("\n");
i=0;
t=0;
r=0;

do{
for(; i<20*(r+1); i++){
for(; t<3*(i+1); t++){
if(t>MPAROLE-1) break;
printf(" %d)%s", t,slot[num_data].parole[t].nome);

if(t<10){
len=strlen(slot[num_data].parole[t].nome);
len=(m_len+offset)-len;
}else if(t>=10 && t<100){
len=strlen(slot[num_data].parole[t].nome);
len=(m_len+offset-1)-len;
}else if(t>=100){
len=strlen(slot[num_data].parole[t].nome);
len=(m_len+offset-2)-len;
}

for(p=0; p<len; p++) printf(" ");
}
printf("\n");
if(t>MPAROLE-1) break;
}
printf("\n Premi un tasto per continuare la visualizzazione...\n");
getchar();
r++;
}while(r<9);

pulisci();

do{
printf("\n Cosa vuoi fare?\n");
printf(" 1) Modifica una parola\n");
printf(" 2) Cancella una parola\n");
printf(" 3) Cancella piu' parole\n");
printf(" 4) Esci\n\n");

do{
printf(" Immetti la scelta: ");
gets(ch);
num=atoi(ch);
}while(num<1 || num>4);

printf("\n");

switch(num){
case 1:
do{
printf(" Inserisci il numero del record da modificare: ");
gets(ch);
num_rec=atoi(ch);
/* atoi(ch) restituisce zero se ch Ë zero o Ë una lettera, se si verifica
quest'ultimo caso, imposto la variabile num_rec al valore max+1 cosi
son sicuro che non esce dal while.*/
if(num_rec==0 && ch[0]!='0') num_rec=MPAROLE;
}while(num_rec<0 || num_rec>MPAROLE-1);

printf(" Nome vecchio: %s\n", slot[num_data].parole[num_rec].nome);
printf(" Nome nuovo (vuoto per eliminarla): ");
gets(slot[num_data].parole[num_rec].nome);
if(slot[num_data].parole[num_rec].nome[0]=='\0') cont_records[num_data]--;
num3=1;

break;
case 2:
do{
printf(" Inserisci il numero del record da cancellare: ");
gets(ch);
num_rec=atoi(ch);
if(num_rec==0 && ch[0]!='0') num_rec=MPAROLE;
}while(num_rec<0 || num_rec>MPAROLE-1);

printf("\n Ho eliminato la seguente parola: %s\n",
slot[num_data].parole[num_rec].nome );
slot[num_data].parole[num_rec].nome[0]='\0';
cont_records[num_data]--;
num3=1;

break;
case 3:
do{
printf(" Inserisci il numero della prima parola: ");
gets(ch);
num_rec=atoi(ch);
if(num_rec==0 && ch[0]!='0') num_rec=MPAROLE;

printf(" Inserisci il numero dell'ultima parola: ");
gets(ch);
num_rec2=atoi(ch);
if(num_rec2==0 && ch[0]!='0') num_rec2=MPAROLE;

}while(num_rec<0 || num_rec>MPAROLE-1 || num_rec2<0 || num_rec2>MPAROLE-1
|| num_rec>num_rec2);

printf("\n");
for(i=num_rec; i<=num_rec2; i++){
printf(" Ho eliminato la seguente parola: %s\n",
slot[num_data].parole[i].nome );
slot[num_data].parole[i].nome[0]='\0';
cont_records[num_data]--;
}
num3=1;

break;
case 4:
num3=0;
break;
}

}while(num3);

pulisci();
return;
}

void pulisci(void){
#ifdef WIN32
system("cls"); //for win
#else
system("clear"); //for linux e mac
#endif
}

//End



A quanto pare, sotto compilazione da Linux, pare fungere. Ma... Bho'.

TheCube
23-03-07, 17:38
gli header sono dove devono essere?
a seguito di aggiornamento sono cambiate le opzioni di default del compilatore?

Nella riga seguente l'"a capo" che si vede spero sia un errore di copia e incolla... altrimenti il problema è lì:

printf("\n Inserisci 1 nei database da randomizzare, 0 in caso
contrario.\n\n");
Probabilmente c'è un fine riga che non dovrebbe esserci...

iGodness
23-03-07, 17:46
Non credo siano cambiate le opzioni di default del compilatore, ma nel caso fosse successo cosi', come faccio a controllare?