#include const char *usage = "\ wrap - wrap a text file.\n\ Usage: wrap \n"; int main(int argc, char **argv) { if ( argc < 3 ) { printf("%s", usage); return 1; } FILE *in = fopen(argv[1], "r"); FILE *out = fopen(argv[2], "w"); int cn = 0; char c = 0x00; if ( !in || !out ) { printf("Failed to open input/output file.\n"); in ? fclose(in) : 0 ; out ? fclose(out) : 0 ; return 1; } while ( !feof(in) ) { c = fgetc(in); if ( cn > 60 && ( c == ' ' || c == '\n' || c == '\t' )) { fputc('\n', out); cn = 0; if ( c != '\t' ) continue; } fputc(c, out); cn++; } fclose(in); fclose(out); return 0; }