Basically I wanted to take in input some strings (arrays of char) from a file to then printf them into another file The problem is that when i want to print, nothing happens and I get the file where i wanted to print my srings in of some GIGABYTES of size

I used a struct i tried the file opening with append and write methods

int main(){

//input with a method

int lung;

lung=input(&lung);

FILE *fp;

struct vetture{
    char plate[LUNG_MAX];
    char type[LUNG_MAX];
    char kind[LUNG_MAX];
    char optional[LUNG_MAX];
}machine[lung];

int i;

fp = fopen("Auto.txt","r");

if (fp == NULL)
    printf("ERROR ON FILE OPENING");
else{
    while (!feof(fp)){
        fscanf(fp, "%s",&machine[i].plate);
        fscanf(fp, "%s",&machine[i].kind);
        fscanf(fp, "%s",&machine[i].type);
        fscanf(fp, "%s",&machine[i].optional);
        i++;
    }
    fclose(fp);
}


fclose(fp);


for(i=0;i<lung;i++)
    printf("\n%s\t%s\t%s\t%s",machine[i].plate,machine[i].kind,machine[i].type,machine[i].optional);


for(i=0;i<lung;i++){    
    if(strcmp(machine[i].optional,"\0")==0){
            printf("\nThe plate of the car with the optional is :%s",machine[i].plate);
    }
}   



fp = fopen("Stampa.txt","w");

if(fp==NULL)
    printf("ERROR ON FILE OPENING");
else
    while(!feof(fp)){
        fprintf(fp,"%s\t",machine[0].plate);
    }




fclose(fp);


return 0;

}

I expect just a simple print into my file and not an error

0 Answers