chunker.

Well, if I can’t sleep, I can at least get my code spit out.

#include [stdio.h]

#define WORKSPACE “./Workspace/”
#define LINE_LENGTH 160

int chunk_size = 43;

main()
{
int i = 0, wrote = 0;
FILE *fp;
char filename[LINE_LENGTH], insuck[LINE_LENGTH];

sprintf(filename, “%s%d”, WORKSPACE, i++);
if ((fp = fopen(filename, “w”)) == NULL) exit(1);

while (fgets(insuck, LINE_LENGTH, stdin) != NULL) {
fprintf(fp, “%s”, insuck); wrote++;
if (wrote >= chunk_size) {
fclose(fp);
sprintf(filename, “%s%d”, WORKSPACE, i++);
if ((fp = fopen(filename, “w”)) == NULL) exit(1);
wrote = 0;
}
}

fclose(fp);

exit(0);
}

Leave a Reply