You can create a function that writes the number to pieces, and insert the dots 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 it in the place of printf()
call to this function:
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 non-negative integers, but this is for the specific case of line counting (or anything else). If you need a function that handles negative numbers, just treat the possibility of a minus sign before the first class.
Finally, it is also possible to replace this parameter FILE *
by a char *
and exchange calls to fprintf()
for sprintf()
, if you want, but be careful to size up your arrays correctly and also finish the string with a \0
, that does not need to do with the FILE *
.
You need to give more context to what you’re doing, provide more code.
– Maniero
plus the rest of the code is useless, because it has nothing that can help with that, and this MYSQL_ROW is from the mysql API. the very point is that the Rows returns as a string, if it were integer it would be easier.
– carolzinha