是否有任何简单的功能或策略可以帮助我fprintf
从每100个字符移至下一行时从缓冲区中移到文件上?
一个简单的循环:
#include <stdio.h>
#define MAX_LINE 100
int main(void)
{
char str[10000];
char *ptr = str;
int size;
fgets(ptr, sizeof str, stdin);
do {
/* write a maximum of 100 chars to file and a trailing new line */
/* size stores the number of chars written - trailing nl */
size = fprintf(stdout, "%.*s\n", MAX_LINE, ptr) - 1;
/* increment the ptr size positions */
ptr += size;
/* if (end-of-buffer - size < 100) exit loop */
} while (size >= MAX_LINE);
return 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句