c - Dividing a file into equal parts of 128 bytes each -


int main() {     file *fe, *fs;     unsigned char buffer[128];     int bytesreader;     int i;     char cad[100];      fe = fopen("pg2000.txt", "rb");     fseek(fe, 0l, seek_end);     int x = ftell(fe);     printf("%d",x);     int x = ftell(fe);     int result=x/128;      for(i=0;i<result;i++)     {         bytesreader = fread(buffer, 1, 128, fe)         sprintf(cad, "a%d", i);         strcat(cad,".txt");         printf("%s\n", cad);         fs = fopen(cad, "wb");         fwrite(buffer, 1, bytesreader, fs);         fclose(fs);     }      fclose(fe);      return 0; } 

i want split file equal parts of 128 bytes each, when file large access violation, don't understand...

fe = fopen("pg2000.txt", "rb");  int x = ftell(fe); int result=x/128; 

x here zero. if fopen() suceeds. need check for.

also, whozcraig points out, fclose() fs should inside loop.

and this

for(i=0;i=result;i++)          ^ 

is not had in mind either.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

html - Repeat image to extend header to fill screen -

javascript - Backbone.js getting target attribute -