chunker.

Aug. 5th, 2001 02:43 am
scottobear: (Default)
[personal profile] scottobear
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);
}
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

scottobear: (Default)
scott von berg

April 2017

S M T W T F S
       1
2 345678
9 10 11 12 13 14 15
16 1718 19 20 21 22
23 2425 26 2728 29
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 21st, 2026 05:56 pm
Powered by Dreamwidth Studios