I'm currently learning C with K&R, i'm right now in the exercise 1-22, but it's a little... hard to understand (at least for me). It says:
Write a program to "fold" long input lines into two or more shorter lines after the last non-blank character that occurs before the n-th column of input. Make sure your program does something intelligent with very long line, and if there are no blanks or tabs before the specified column.
I've done this:
#include <stdio.h> void seccionar(char to[], char from[]) { int a = 0,b = 0, i = 0; int max = 0; while(from[i] != '\0'){ if(max <= 80) to[a] = from[i]; if(max == 80){ if(to[a] == ' ') to[a] = '\n'; else { for(;to[a] != ' '; --a) ++b; to[a] = '\n'; max = 0; a = a + b;} b = 0; } ++a; ++i; ++max;} to[a] = '\0'; } int getline(char s[]) { int c, i; for(i=0; (c=getchar()) != EOF; ++i){ s[i] = c; if(c == '\n') break;} ++i; s[i] = '\0'; return i; } int main() { char from[10]; char to[10]; while(getline(from) > 1){ seccionar(to, from); printf("%s", to);} return 0; } Does this matches with the exercise?