It is impossible to do something like this fputs(4, fptOut);because fputs does not like integers. How can I get around this?
fputs(4, fptOut);
Execution is fputs("4", fptOut);not an option because I work with a counter value.
fputs("4", fptOut);
What about
fprintf(fptOut, "%d", yourCounter); // yourCounter of type int in this case
The documentation fprintfcan be found here .
fprintf
fprintf(fptOut, "%d", counter);
. , fputs, , sprintf. - :
#include <stdio.h> #include <stdint.h> int main(int argc, char **argv){ uint32_t counter = 4; char buffer[16] = {0}; FILE * fptOut = 0; /* ... code to open your file goes here ... */ sprintf(buffer, "%d", counter); fputs(buffer, fptOut); return 0; }
6 , fputs
fputs
char buf[12], *p = buf + 11; *p = 0; for (; n; n /= 10) *--p = n % 10 + '0'; fputs(p, fptOut);
, , fprintf.