You can create a function that writes the number to pieces, and insert the points between them:
void
escrever_numero(unsigned int n, FILE * stream) {
char buf[10];
char * ptr = buf;
size_t nchar, i, j;
// escreve número no buffer
nchar = sprintf(buf, "%d", n);
// Quantos dígitos preciso escrever para a primeira classe?
i = nchar % 3; if (!i) i = 3;
// escrever a primeira classe
fprintf(stream, "%.*s", i, ptr);
// avançar
ptr += i;
// enquanto ainda houver classes para escrever,
// escreva um ponto e depois a classe
while (*ptr) {
fputc('.', stream);
fprintf(stream, "%.3s", ptr);
// não esqueça de avançar o ponteiro
ptr += 3;
}
}
Then just put the call to this function in place of printf()
:
void sql_rows(MYSQL_ROW sql) {
puts("a quantidade de rows é ");
escrever_numero(sql->row[0], stdout);
puts("\n");
}
Note that the function I wrote only works with nonnegative integers, but this is for the specific case of counting lines (or anything else). If you need a function that treats negative numbers, just treat the possibility of a minus sign before the first class.
Finally, you can also override this FILE *
parameter with a char *
and switch calls to fprintf()
with sprintf()
if you want, but be careful to size your arrays correctly and also end the string with a FILE *
, which does not have to do with %code% .