The scanf keeps being skipped

后端 未结 3 1755
独厮守ぢ
独厮守ぢ 2020-12-22 02:32

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 quest

3条回答
  •  执念已碎
    2020-12-22 02:59

    #include 
    
    struct  s_tiempo
    {
        int minutos;
        int segundos;
    };
    
    struct carrera
    {
            int nro_corredor;   // guarda nro de corredor
            struct s_tiempo tiempo;      // guarda el tiempo que tardo el corredor
    };
    
    struct datos
    {
            int nro_corredor;  // guarda nro de corredor
            char apellido[20];
            char nombres[20];
            char direccion[30];
    };
    
    bool leerdatos( struct datos *); //declaro la funcion leer
    
    int main (void)
    {
        int cp; //cantidad de participantes.
    
        printf("Ingrese la cantidad de participantes: ");
        if( 1 != scanf(" %d",&cp) )
        {
            perror( "failed getting participantes using scanf()");
            return( 1 );
        }
        // implied else
    
        struct datos corredor[cp];
        struct carrera carreras[cp]; // should get compiler warning due to this not being used
        printf("A continuacion, ingrese los datos de los corredores: \n");
    
        for(int i=0;i

提交回复
热议问题