我如何获得输入切断或在某一个点环绕?(How do I get the input to cut o

2019-07-04 16:46发布

Alrighty,所以一天一点的是计算器上后,我了解到它是在这个网站:)我最终得到我的程序的工作是非常有用的。 我能得到的文本文件的无限量在命令行上,并显示他们的! 所以它看起来像这样:


CMD控制台

C:\ Users \用户名\桌面> wrapfile.exe hello.txt的how.txt。 are.txt you.txt random.txt

你好,你今天好吗? 我希望你做得很好。 这只是一个测试,看看我多少能适合在屏幕上。


现在,我瓦纳建立在这个节目。 我将如何得到这个新发现的文字环绕? 就像,如果你想让它说,每40个字符左右,文本跳转到下一行......我们怎么能去这样做类似的东西?

再次感谢!

这里是我正在使用的代码:

#include <stdio.h>
#include <stdlib.h>


int main(int argc, char **argv)
{

    int l = 1;
        while(l != argc)
{
        FILE *fp; // declaring variable


        fp = fopen(argv[l], "rb");
        l++;


    if (fp != NULL) // checks the return value from fopen
    {
        int i = 1;
        do
        {
            i = fgetc(fp);     // scans the file 
            printf("%c",i);
            printf(" ");
        }
        while(i!=-1);
        fclose(fp);
    }
    else
    {
        printf("Error.\n");
    }
}


}

Answer 1:

好了,我们开始吧...这看起来你有点不同,但是这是ISO / ANSI C标准的1989年。

int main(int argc, char **argv)
{
     FILE *fd = NULL;
     char linebuf[40];
     int arg = 1;

     while (arg < argc) {
         fd = fopen(argv[arg], "r");
         if (NULL != fd) {
              /* fgets(char *buf, size_t buflen, FILE *fd): returns NULL on error. */
              while (NULL != fgets(linebuf, sizeof(linebuf), fd)) {
                  printf("%s\n", linebuf);
              }
              fclose(fd);
         } else {
              fprintf(stderr, "Cannot open \"%s\"\n", argv[arg]);
         }
         ++arg;
     }
 }


文章来源: How do I get the input to cut off or wrap around at a certain point?
标签: c text console cmd