Multiple strings, Truncate line at 80 characters

前端 未结 5 914
无人共我
无人共我 2021-02-02 05:57

I\'m new to awk and sed, and I\'m looking for a way to truncate a line at 80 characters, but I\'m printing several strings in that line using printf. The last two strings are th

5条回答
  •  滥情空心
    2021-02-02 06:20

    How about a C version?

    #include 
    int maxline = 80;
    int main(int argc, char* argv[])
    {
        char line[2048];
        if ((argc>1) && (atoi(argv[1]) > 0)) {
            maxline = atoi(argv[1]);
        }
        while (fgets(line, sizeof(line), stdin)) {
            line[maxline] = '\0';
            printf("%s\n", line);
        }
    }
    

提交回复
热议问题