I'v written the program below,
but I'v been told its too "intense"
Any ideas on how I can get the same results but with a simpler program?
#define MAX_SIZE 10000
char buf[MAX_SIZE], name[1000];
int min(int a, int b) {
return a<b?a:b;
}
int main(int argc, char** argv) {
FILE *out, *in;
int size, i, cnt, temp;
if(argc == 3 && strcmp(argv[1], "-e") == 0) {
in = fopen(argv[argc-1], "rb");
while(1) {
if(fgets(buf, MAX_SIZE, in) == NULL)
break;
printf("%s\n", buf);
fflush(stdout);
sscanf(buf, " %d$%s", &size, name);
//temp = strlen(name);
//name[temp] = '_';
//name[temp+1] = 0;
printf("%s %d\n", name, size);
fflush(stdout);
out = fopen(name, "wb");
while(size > 0) {
cnt = fread(buf, 1, min(MAX_SIZE, size), in);
fwrite(buf, 1, cnt, out);
size -= cnt;
}
fflush(out);
fclose(out);
}
}else if(argc > 3 && strcmp(argv[1], "-c") == 0){
out = fopen(argv[argc-1], "wb");
for(i=2; i<argc-1; i++) {
in = fopen(argv[i], "rb");
fseek(in, 0, SEEK_END);
size = ftell(in);
fprintf(out, "%d$%s\n", size, argv[i]);
fseek(in, 0, SEEK_SET);
while((cnt = fread(buf, 1, MAX_SIZE, in)) != 0)
fwrite(buf, 1, cnt, out);
fclose(in);
}
fclose(out);
}
return 0;
}