如何在C中的10个字符后插入新行?

时间:2017-02-17 22:11:34

标签: c

我一次从标准输入读取一个字符的数据,并将结果输出到标准输出。每10个字符,我想要一个新的行。例如:

输入 -

123456789101112

输出 -

1234567891
01112

这是我到目前为止所做的,但它不起作用。

if(numChars = 10) {
    printf("\n");
    numChars = 0;
}

1 个答案:

答案 0 :(得分:1)

#include <windows.h>

int main()
{
    char test[] = "123456789101112123133431234567891011121231334312345678910111212313343";

    int i = 0;
    while (i < strlen(test))
    {
        printf("%c", test[i++]);
        if (i % 10 == 0) {
            printf("\n");
        }
    }
    return 0;
}

enter image description here