This repository has been archived on 2026-05-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

42 lines
672 B
C
Raw Permalink Normal View History

2026-05-18 12:31:43 -04:00
#include <stdio.h>
const char *usage = "\
wrap - wrap a text file.\n\
Usage: wrap <infile> <outfile>\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;
}