K&R第1章 – 练习22解决方案,你觉得怎么样?
发布时间:2020-12-16 05:33:46 所属栏目:百科 来源:网络整理
导读:我正在从K r学习C作为第一语言,我只是想问一下,如果你认为这个练习是正确的解决方法,我知道它可能没有你想要的那么完整,但我想要看法,所以我知道我正在学习C. 谢谢 /* Exercise 1-22. Write a program to "fold" long input lines into two or * more shorte
我正在从K& r学习C作为第一语言,我只是想问一下,如果你认为这个练习是正确的解决方法,我知道它可能没有你想要的那么完整,但我想要看法,所以我知道我正在学习C.
谢谢 /* Exercise 1-22. Write a program to "fold" long input lines into two or * more shorter lines,after the last non-blank character that occurs * before then n-th column of input. Make sure your program does something * intelligent with very long lines,and if there are no blanks or tabs * before the specified column. * * ~svr * * [NOTE: Unfinished,but functional in a generic capacity] * Todo: * Handling of spaceless lines * Handling of lines consisting entirely of whitespace */ #include <stdio.h> #define FOLD 25 #define MAX 200 #define NEWLINE 'n' #define BLANK ' ' #define DELIM 5 #define TAB 't' int main(void) { int line = 0,space = 0,newls = 0,i = 0,c = 0,j = 0; char array[MAX] = {0}; while((c = getchar()) != EOF) { ++line; if(c == NEWLINE) ++newls; if((FOLD - line) < DELIM) { if(c == BLANK) { if(newls > 0) { c = BLANK; newls = 0; } else c = NEWLINE; line = 0; } } array[i++] = c; } for(line = 0; line < i; line++) { if(array[0] == NEWLINE) ; else printf("%c",array[line]); } return 0; } 解决方法
我相信你在这个艰难的轨道上,但有一些可读性的指针:
>评论你的东西 if(array[0] != NEWLINE) { printf("%c",array[line]); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |