SHARE
TWEET

Untitled

puma7953 Nov 17th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int split_n(char *argv[], FILE *file_ptr){
  2.     FILE *file_ptr_new;
  3.     char name[100], buffer[100], c;
  4.     int kol = 0;
  5.  
  6.     struct stat buf;                                     //Определение размера исходного файла
  7.     stat(argv[1], &buf);
  8.     long size, number_of_items_transferred = 0;
  9.     size = buf.st_size;
  10.     printf("Source file size: %lu\n", size);
  11.  
  12.     long new_size = 1 + size / atoi(argv[3]);       //Размер новых файлов
  13.     printf("New file size: %lu\n", new_size);
  14.  
  15.     for (int i = 0; ; i++){
  16.         kol = 0;
  17.  
  18.         strcpy(name, argv[5]);                   //Создание нового файла
  19.         itoa(i, buffer, 10);
  20.         strcat(name, buffer);
  21.         strcat(name, ".txt");
  22.         file_ptr_new = fopen(name, "wb");
  23.  
  24.         while (number_of_items_transferred < size){
  25.  
  26.             if (kol < new_size){
  27.                 c = getc(file_ptr);
  28.                 fputc(c, file_ptr_new);
  29.                 number_of_items_transferred++;
  30.                 kol++;
  31.             }
  32.  
  33.             if (kol == new_size){
  34.                 fclose(file_ptr_new);
  35.                 break;
  36.             }
  37.  
  38.             if (c == EOF){
  39.                 fclose(file_ptr_new);
  40.                 return 0;
  41.             }
  42.         }
  43.         fclose(file_ptr_new);
  44.         return 0;
  45.    }
  46.  
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top