Good afternoon! (EDITED)
I'm doing a work in C
language, where I have to display the information stored in a text file in the console, but it is mandatory to pass all information to% dynamic% of structures.
I think I've already done something, but when I try to save the specialty in vetores
, the file ends up saving the next words.
Ex: variável
is saving "Joao Silva" and v->nome
is saving "Neurology 9.30 - 17.00" and I intend to save only "Neurology".
Can someone help me?
struct hora_entrada{int horas, minutos;};
struct hora_saida{int horas, minutos;};
typedef struct medico med, *p_med;
struct medico{
char nome[ST_TAM];
char especialidade[ST_TAM];
struct hora_entrada h_e;
struct hora_saida h_s;
};
int le_dados (){
FILE *f, *g;
med *v;
f=fopen("medico.txt", "rt");
g=fopen("paciente.txt", "rt");
if (f==NULL || g==NULL){
printf("Erro no acesso ao ficheiro.\n");
return 0;
}
v=malloc(sizeof(med));
if (v==NULL){
printf("Erro na alocaçao de memoria.\n");
return 0;
}
while ((fscanf(f,"%49[^\n] %49[^\n]",v->nome, v->especialidade))==2 )
printf("%s\n%s",v->nome, v->especialidade);
fclose(f);
}