Hi everyone I'm having a nightmare while trying to figure out why the fprintf() function is not writing the string to the file.
I would say that I'm 95% sure that the problem is on the highlighted line down in the code sample because when I'm printing the exact same thing to the console (with printf()) is indeed printing the string that I need.
for (int i = 1; i <= nmappers; i++)
{
    if (fork() == 0) //SI ENTRA A ESTE IF
    {
        sprintf(nombreArchivo, "split%d", i);
        ptrLectura = fopen(nombreArchivo, "r");
        sprintf(nombreArchivo, "buf%d", i);
        ptrEscritura = fopen(nombreArchivo, "w");
        while ((caracter = fgetc(ptrLectura)) != EOF)
        {
            if (caracter != ' ' && caracter != '\n' && !encontroCadena)
            {
                printf("111\n");
                strncat(cadena, &caracter, 1); //Pa que sirva toca con &
                ncol++;
                encontroCadena = true;
            }
            else if (caracter != ' ' && caracter != '\n' && encontroCadena)
            {
                printf("222\n");
                strncat(cadena, &caracter, 1); //Pa que sirva toca con &
            }
            else if (caracter == ' ')
            {
                printf("333\n");
                encontroCadena = false;
            }
            if (caracter == '\n')
            {
                printf("%s\n", cadena);
                printf("444\n");
                fprintf(ptrEscritura, "%s", cadena); //PROBLEM'S PROBABLY HERE
                ncol = 0;
            }
        }
        fflush(ptrEscritura);
        fclose(ptrLectura);
        fclose(ptrEscritura);
        exit(0);
    }
}
PS: The files in wich I want to write the strings are being create succesfully, but the fprintf() function is not working! Also I've tried changing it for fputs(), neither worked.
I will appreciate a lot the help that you could provide to me!
 
     
    