in effetti senza quello compila
però ora non parte proprio
lo analizzo un altro po'
Moderatore: Staff

jimmy_page_89 ha scritto:in effetti senza quello compila
però ora non parte proprio
lo analizzo un altro po'

Mario Vanoni ha scritto:Oggi e domani non ho tempo, nipotina di 13 mesi!
Concordo con j0kers, lo stesso errore tuo,
sempre nelle righe dove usi "int N".

#include <stdio.h>
#include <stdlib.h>
#define N 734
#define TA 200
void print_menu();
void open_file(FILE **fp, char buf[TA], int *vect);
void add(char buf[TA], int *vect);
void rem(char buf[TA], int *vect);
void check_less(int vect[N]);
void check_single(char buf[TA], int vect[N]);
void gen_less(FILE **fp, int vect[N]);
void saving_all(FILE **fp, int vect[N], int *chs);
int main()
{
FILE *fp;
char buf[TA];
int vect[N];
int chs=0, opt=0;
open_file(&fp, buf, vect);
while(chs==0)
{
print_menu(); //lo so che è inutile, ma mi piace mettere così :P
fgets(buf, TA, stdin);
sscanf(buf, "%d", &opt);
switch(opt)
{
case 1:
add(buf, vect);
break;
case 2:
rem(buf, vect);
break;
case 3:
check_less(vect);
break;
case 4:
check_single(buf, vect);
break;
case 5:
gen_less(&fp, vect);
break;
case 6:
printf("Sto Salvando..\n");
saving_all(&fp, vect, &chs);
printf("Uscita\n");
break;
default:
printf("Comando Errato\n");
break;
}
}
return EXIT_SUCCESS;
}
void open_file(FILE **fp, char buf[TA], int *vect)
{
int opt, i=0, chk=0;
if(((*fp)=fopen("figu.txt","r")) == NULL)
{
while(chk == 0)
{
printf("Il file non esiste! Che vuoi fare?\n");
printf("1:Crea Nuovo File\n");
printf("2:Esci\n");
fgets(buf, TA, stdin);
sscanf(buf, "%d", &opt);
switch(opt)
{
case 1:
if(((*fp)=fopen("figu.txt","w"))==NULL)
{
printf("Errore Apertura File!\n");
exit(1);
}
fclose(*fp);
for(i=0;i<N;i++)
vect[i]=0;
chk=1;
break;
case 2:
printf("Uscita\n");
chk=1;
break;
default:
printf("Comando Errato\n");
break;
}
}
}
else
{
while((fscanf((*fp), "%d", vect[i])) == 1 && !feof(*fp))
i++;
fclose(*fp);
}
}
void print_menu()
{
printf("1:Aggiungi Figurine\n");
printf("2:Rimuovi Figurine\n");
printf("3:Figurine Mancanti\n");
printf("4:Controlla Figurina\n");
printf("5:Genera Mancanti\n");
printf("6:Esci\n");
}
void add(char buf[TA], int *vect)
{
int num, chk;
printf("TAerminare con 0\n");
while(chk == 0)
{
fgets(buf, TA, stdin);
sscanf(buf, "%d", &num);
if(num == 0)
chk=1;
else if(num > N)
printf("Numero TAroppo Grande\n");
else
{
if(vect[num-1] == 1)
printf("Figurina Già Presente\n");
else
vect[num-1]=1;
}
}
}
void rem(char buf[TA], int *vect)
{
int num, chk;
printf("Terminare con 0\n");
while(chk == 0)
{
fgets(buf, TA, stdin);
sscanf(buf, "%d", &num);
if(num == 0)
chk=1;
else if(num > N)
printf("Numero TAroppo Grande\n");
else
{
if(vect[num-1] == 0)
printf("Figurina Già Assente\n");
else
vect[num-1]=0;
}
}
}
void check_less(int vect[N])
{
int i, num=0;
for(i=0;i<N;i++)
if(vect[i] == 0)
num++;
printf("%d\n", num);
}
void check_single(char buf[TA], int vect[N])
{
int num, chk=0;
while(chk == 0)
{
fgets(buf, TA, stdin);
sscanf(buf, "%d", &num);
if(num==0)
break;
else if(num > N)
printf("Numero TAroppo Grande\n");
else
{
if(vect[num-1] == 1)
printf("Presente\n");
else
printf("Assente\n");
}
}
}
void gen_less(FILE **fp, int vect[N])
{
int i;
if(((*fp)=fopen("mancanti.txt","w"))==NULL)
{
printf("Errore Apertura File!");
exit(1);
}
for(i=0;i<N;i++)
if(vect[i]==0)
fprintf((*fp), "%d ", i+1);
fclose(*fp);
}
void saving_all(FILE **fp, int vect[N], int *chs)
{
int i;
if(((*fp)=fopen("figu.txt","w")) == NULL)
{
printf("Errore Apertura File");
exit(1);
}
for(i=0;i<N;i++)
fprintf((*fp), "%d ", vect[i]);
(*chs)=1;
fclose(*fp);
}Mario Vanoni ha scritto:PS Programma _ben_ riscritto, non mi piacciono, sono l'eccezione,
i messaggi, ma usando tastature US-ASCII e sempre LANG=US ...

case 2:
printf("Uscita\n");
exit(0);
break;

/home/liguori/figs/main.c|96|warning: format ‘%d’ expects type ‘int *’, but argument 3 has type ‘int’|

jimmy_page_89 ha scritto:tutto a posto, dovevo solo mettere una exit al case 2: nello switch della open_file
- Codice: Seleziona tutto
case 2:
printf("Uscita\n");
exit(0);
break;
se avete qualche altro suggerimento non esitate
root@va2:~# gcc -O2 -s -static -o cavolo cavolo3.c
root@va2:~# cavolo
Il file non esiste! Che vuoi fare?
1:Crea Nuovo File
2:Esci
1
1:Aggiungi Figurine
2:Rimuovi Figurine
3:Figurine Mancanti
4:Controlla Figurina
5:Genera Mancanti
6:Esci
6
Sto Salvando..
Uscita
root@va2:~# cavolo
Segmentation fault
root@va2:~#

jimmy_page_89 ha scritto:alla riga 96 mi da questo warning
- Codice: Seleziona tutto
/home/liguori/figs/main.c|96|warning: format ‘%d’ expects type ‘int *’, but argument 3 has type ‘int’|
anche se il programma gira bene
EDIT non gira un piffero
RIEDIT: risolto, era banale, bastava sostituire nella fscanf vect[i] con &vect[i]
ora tutto funziona

Mario Vanoni ha scritto:Per i messaggi:
printf("Numero TAroppo Grande\n");
printf("Figurina Già Presente\n");
Nel nvi le lettere accentate diventano illegibili,
se usi un sistema 7-bit US-ASCII.
Idem con il grep, less e more.


jimmy_page_89 ha scritto:sono su una semplice tastiera IT
a questo punto per usarlo dappertutto sostituisco le accentate con lettera + apostrofo, o non c'è neppure quello sulla US-ASCII?
root@va2:~# ls eeee
ls: cannot access eeee: No such file or directory
root@va2:~#

Visitano il forum: Nessuno e 1 ospite