Error when exporting a lot of data from the cmd in C

3

Help, I am trying to export this code from C to a txt redirecting the output when executing it from the cmd, but it hangs up I think because they are too much data (50,000): s what should I do? including variables

char *nombre_alumno[]

char *sexo_alumno[]

You can not even see the code in yellow as in the photo, it appears all white as if you did not recognize it as an arrangement ** There, in the picture, I wrote that after the names and the sex, another 50,000 values followed.

    int main()
{
    char *nombre_alumno[] = {"Zina","Bartley","Primavera",.......,>>>50.000 datos mas<<,....};
    char *sexo_alumno[] = {"f","m","f","m","m","f",....,>>>50.000 datos mas<<<,....};
    int i;
    srand (getpid());       //Semilla para generar números aleatorios
    for(i=0;i<(sizeof(nombre_alumno)/sizeof(nombre_alumno[0]));i++)
    {
        printf("INSERT INTO ALUMNO VALUES (%d,'%s',%d,%d,'%s',%s);\n"
            ,Matricula_alumno,nombre_alumno[i],NUMEROS_AL_EDAD(),NUMEROS_AL_SEMESTRE(),sexo_alumno[i],NUMEROS_AL_CARRERA());
    }
}

int NUMEROS_AL_EDAD()
{
    int num;
    //numero = rand () % (N-M+1) + M;   // Este está entre M (valor minimo) y N (valor maximo)
    num = rand() % 54 + 17;  //Numeros aleatorios entre 17 y
    num = num + 1; 
    return num;
}
int NUMEROS_AL_SEMESTRE()
{
    int num;
    num = rand() % 11 + 1; //Numeros aleatorios entre 1 y 12
    num = num + 1; 
    return num;
}
int NUMEROS_AL_CARRERA()
{
    int num;
    num = rand() % 13 + 1; //Numeros aleatorios entre 1 y 13
    num = num + 1; 
    return num;
}
    
asked by EmiliOrtega 28.08.2017 в 18:05
source

1 answer

1

To me that printf I do not like a hair:

printf("INSERT INTO ALUMNO VALUES (%d,'%s',%d,%d,'%s',%s);\n"
       ,Matricula_alumno,nombre_alumno[i],NUMEROS_AL_EDAD(),NUMEROS_AL_SEMESTRE(),sexo_alumno[i],NUMEROS_AL_CARRERA());

If we look more closely:

printf("INSERT INTO ALUMNO VALUES (%d,'%s',%d,%d,'%s',%s);\n",
//                                                    ^^
       Matricula_alumno,
       nombre_alumno[i],
       NUMEROS_AL_EDAD(),
       NUMEROS_AL_SEMESTRE(),
       sexo_alumno[i],
       NUMEROS_AL_CARRERA());
//     ^^^^^^^^^^^^^^^^^^^^

   int NUMEROS_AL_CARRERA()
// ^^^
{
}

Summarizing ... printf is going to treat the 6th parameter as if it were a string of characters and yet you are passing a whole ... or else you end up printing garbage or the program ends up ... Modern operating systems do not usually make you too funny that you access memory that does not belong to you.

    
answered by 29.08.2017 в 08:51