After I formatted the "direccion"'s scanf in function "leerdatos", it skip the "nro_corredor" in the second 'for' loop.
I've already read the related questions but still not getting an answer.
What can I do to solve it?
#include <stdio.h>
typedef struct {
int minutos;
int segundos;
} s_tiempo;
typedef struct {
int nro_corredor; // guarda nro de corredor
s_tiempo tiempo; // guarda el tiempo que tardo el corredor
} carrera;
typedef struct {
int nro_corredor; // guarda nro de corredor
char apellido[20];
char nombres[20];
char direccion[30];
} datos;
datos leerdatos(); //declaro la funcion leer
int main (void) {
int cp; //cantidad de participantes.
datos aux;
printf("Ingrese la cantidad de participantes: ");
scanf("%d",&cp);
datos corredor[cp];
carrera carreras[cp];
printf("A continuacion, ingrese los datos de los corredores:
");
for(int i=0;i<cp;i++){
aux = leerdatos();
corredor[i] = aux;
}
}
datos leerdatos(void) {
datos participante;
printf("
Ingrese el numero de corredor: ");
scanf("%d",&participante.nro_corredor);
printf("
Ingrese el apellido:
");
scanf("%s",participante.apellido);
printf("
Ingrese los nombres:
");
scanf("%s",participante.nombres);
printf("
Ingrese la direccion:
");
scanf(" %s
",participante.direccion);
return(participante);
}
See Question&Answers more detail:os