I am new with programming, after searching and searching, i got some code to work (partially), i can create a struct but i can't print string fields :/
#include <stdio.h>
#define MAX 100
struct vehiculos{
float peso;
int hora;
char *id;
int ferry;
};
void asignar(struct vehiculos llegada[MAX] ...) { // Here i have more parameters, but they are useless in this question...
int id,i;
i=0;
while(!feof(input_file)){
fscanf(input_file,"%f %d %s %d",&llegada[i].peso,&llegada[i].hora,id,&llegada[i].ferry);
llegada[i].id = id;
i++;
}
}
int main(){
struct vehiculos llegada[MAX];
FILE *entrada;
entrada = fopen("proy1.txt","r");
asignar(llegada...);
return 0;
}
My problem is that everything works fine in that "asignar" function, but if i try to print the vehicle's id outside that function, it just print garbage values, however other values like peso, hora and ferry are printed correctly (outside the function)
This works:
void asignar(...){
...
printf("%s", llegada[i].id);
...
}
This doesn't work:
int main(){
...
printf("%s", llegada[i].id);
...
}
Also my compiler says that there are no errors in the code, so i don't know what is the problem here
Can anyone help me? it would be great, Thanks :)