Writing strings to a file
This is a very instructive example of wrong judgement. I understand (correct me if I am wrong) that you went for a low-level write to avoid seemingly unnecessary overhead of FILE * functions offered by a stdio library. Not only it made your code less portable, it in fact made id slower!

The net effect is that your code invokes a system call for each 10 characters.

System call is an extremely expensive operation. It involves switching memory maps from a user to a kernel space, and on top of that it faces who knows how many cache misses. This is exactly the problem stdio solves by internal buffering.

This is how your original code behaves:

~/projects/play/cr/pedro $ time ./original 

real    0m7.929s
user    0m0.484s
sys     0m7.432s


I changed opening a file to 

FILE * file = fopen(fi, "w");


and writing to it to

    fputs(cad, file);


and the new timigs are

~/projects/play/cr/pedro $ time ./with-stdio 

real    0m0.908s
user    0m0.276s
sys     0m0.584s


PS To make it a code review:

You shall #include at least &lt;sys/types.h&gt;, &lt;sys/stat.h&gt;, &lt;fcntl.h&gt; and &lt;time.h&gt;.