ciusss89
02-07-2009, 12:25
Salve ragazzi in fase di compilare di un codice cosi composto, 2 strutture 2 funzioni nel main, il problema è in compilazione di una parte del codice voglio salvere il campo letto all'interno della struttura..(accesso alla struttura all'interno di una funzione non credo che ci siano arrori nel passaggio dei parametri ma non riesco a capire)....
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define name 10
#define campo 4
typedef struct {
int nf;
char ids[campo];
}fid_nf;
typedef struct {
char fornitore[campo];
int prezzo;
}fornitori;
void read(FILE* fin1 , fid_nf*, int, fornitori* );
void idcost(FILE* fin1 , fid_nf*, fornitori*);
int main(int argc, char *argv[]){
fid_nf *str1;
fornitori *str2;
int r;
char in1[name],out1[name];
FILE *fin1,*fout1;
if(argc!=3){
fprintf(stderr,"ERROR IN/OUT");
exit (EXIT_FAILURE);
}
strcpy(in1,argv[1]);
strcpy(out1,argv[2]);
if((fin1=fopen(in1,"r"))==NULL){
fprintf(stderr,"ERROR READ FILE");
exit (EXIT_FAILURE);
}
if((fout1=fopen(out1,"w"))==NULL){
fprintf(stderr,"ERROR WRITE FILE");
exit (EXIT_FAILURE);
}
fscanf(fin1, ("%d") ,&r);
read(fin1,str1,r,str2);
return 0;
}
void read (FILE* fin1 , fid_nf* str1, int r, fornitori* str2 ){
char id[4];
int n,cont;
str1=(fid_nf*)malloc(r*sizeof(fid_nf));
if(str1==NULL){
fprintf(stderr,"ERROR MEMORY IS FULL");
exit (EXIT_FAILURE);
}
while ( fscanf(fin1, "%s%d", &id , &n)!=EOF ){
fid_nf[cont].nf=n;
strcpy(fid_nf[cont].ids, id);
idcost(fin1,str1,str2);
cont++;
}
return;
}
void idcost(FILE* fin1 , fid_nf* str1, fornitori* str2){
return;
}
OUTPUT DEL COMPILATORE DEV C ALLE RIGHE IN ROSSO:
C:\Documents and Settings\giuse\Desktop\esegui\Untitled1.c In function `read':
60 C:\Documents and Settings\giuse\Desktop\esegui\Untitled1.c syntax error before '[' token
61 C:\Documents and Settings\giuse\Desktop\esegui\Untitled1.c syntax error before "fid_nf"
grazie in anticipo a tutti
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define name 10
#define campo 4
typedef struct {
int nf;
char ids[campo];
}fid_nf;
typedef struct {
char fornitore[campo];
int prezzo;
}fornitori;
void read(FILE* fin1 , fid_nf*, int, fornitori* );
void idcost(FILE* fin1 , fid_nf*, fornitori*);
int main(int argc, char *argv[]){
fid_nf *str1;
fornitori *str2;
int r;
char in1[name],out1[name];
FILE *fin1,*fout1;
if(argc!=3){
fprintf(stderr,"ERROR IN/OUT");
exit (EXIT_FAILURE);
}
strcpy(in1,argv[1]);
strcpy(out1,argv[2]);
if((fin1=fopen(in1,"r"))==NULL){
fprintf(stderr,"ERROR READ FILE");
exit (EXIT_FAILURE);
}
if((fout1=fopen(out1,"w"))==NULL){
fprintf(stderr,"ERROR WRITE FILE");
exit (EXIT_FAILURE);
}
fscanf(fin1, ("%d") ,&r);
read(fin1,str1,r,str2);
return 0;
}
void read (FILE* fin1 , fid_nf* str1, int r, fornitori* str2 ){
char id[4];
int n,cont;
str1=(fid_nf*)malloc(r*sizeof(fid_nf));
if(str1==NULL){
fprintf(stderr,"ERROR MEMORY IS FULL");
exit (EXIT_FAILURE);
}
while ( fscanf(fin1, "%s%d", &id , &n)!=EOF ){
fid_nf[cont].nf=n;
strcpy(fid_nf[cont].ids, id);
idcost(fin1,str1,str2);
cont++;
}
return;
}
void idcost(FILE* fin1 , fid_nf* str1, fornitori* str2){
return;
}
OUTPUT DEL COMPILATORE DEV C ALLE RIGHE IN ROSSO:
C:\Documents and Settings\giuse\Desktop\esegui\Untitled1.c In function `read':
60 C:\Documents and Settings\giuse\Desktop\esegui\Untitled1.c syntax error before '[' token
61 C:\Documents and Settings\giuse\Desktop\esegui\Untitled1.c syntax error before "fid_nf"
grazie in anticipo a tutti