I tried to make a program that takes a file and turns it into a bunch of smaller files, but the output files are always empty... can someone tell me where I'm messing up?
Code:#include "windows.h"
#include "stdio.h"
#include "string.h"
void main(){
FILE *fl1, *fl2;
char Fn[255], On[255], end=0;
void *goan;
int Num, Siz, l1, l2, oh, oh2;
printf("Name of file to open: ");
scanf("%s",&Fn);
printf("\nBase name of output files : ");
scanf("%s",&On);
printf("\nNumber of files to make (less than 1,000): ");
scanf("%d",&Num);
printf("\nSize of files : ");
scanf("%d",&Siz);
printf("\n\nWorking: ");
fl1=fopen(Fn,"r");
for(l1=0;l1<Num;l1++){
On[0]=(char)(48+(int)(l1/100));
On[1]=(char)(48+(int)((l1-100*((int)On[0]-48))/10));
On[2]=(char)(48+(l1-100*((int)On[0]-48)-10*((int)On[1]-48)));
fl2=fopen(On,"w");
goan=malloc((0x1000*Siz));
if(goan==NULL){
printf("\n\n\tFAILURE\n");
fclose(fl1);
fclose(fl2);
scanf("%c",end);
scanf("%c",end);
return;
}
oh=fread(goan,1,(0x1000*Siz),fl1);
printf("\noh= %d",oh);
oh2=fwrite(goan,1,oh,fl2);
if((0x1000*Siz)!=oh2){
printf("\nLooks like an error, but I could be wrong...");
}
fclose(fl1);
free(goan);
}
fclose(fl1);
printf("\n\n\tDone\n");
scanf("%c",end);
scanf("%c",end);
}