Writing an integer to a file with fputs()

前端 未结 4 1359
终归单人心
终归单人心 2021-01-04 13:21

It\'s not possible to do something like fputs(4, fptOut); because fputs doesn\'t like integers. How can I work around this?

Doing fputs(\"4\", fpt

4条回答
  •  被撕碎了的回忆
    2021-01-04 13:45

    I know 6 years too late but if you really wanted to use fputs

    char buf[12], *p = buf + 11;
    *p = 0;
    for (; n; n /= 10)
        *--p = n % 10 + '0';
    fputs(p, fptOut);
    

    Should also note this is for educational purpose, you should stick with fprintf.

提交回复
热议问题