Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/stat.h>
  5.  
  6. int main(int argc, char ** argv)
  7.  {
  8.     char file_name[128];
  9.     strcpy(file_name, argv[1]);
  10.     FILE *p = fopen(file_name, "rb");
  11.  
  12.     char c;
  13.     struct stat st;
  14.     stat(argv[1], &st);
  15.     int file_length = st.st_size;
  16.     fclose(p);
  17.  
  18.     char action;
  19.  
  20.     action = argv[2][0];
  21.     int bits = atoi(argv[3]);
  22.     char file_output[128];
  23.     strcpy(file_output, argv[4]);
  24.  
  25.  
  26.  
  27.     if (action == 's')
  28.     {
  29.  
  30.         int length = strlen(file_output);
  31.         strcat(file_output,"_0.txt");
  32.         length++;
  33.  
  34.         int n = file_length / bits;
  35.         FILE *p = fopen(file_name, "rb");
  36.         for (int i = 0; i < n; i++)
  37.         {
  38.             file_output[length] = i + '0';
  39.             printf("%s", file_output);
  40.             FILE *d = fopen(file_output, "wb");
  41.             for (int j = 0; j < bits; j++)
  42.             {
  43.                 char k;
  44.                 if ((k = fgetc(p)) == EOF)
  45.                     return 0;
  46.                 fputc(k, d);
  47.             }
  48.             fclose(d);
  49.         }
  50.     }
  51.  
  52.     else if (action == 'n')
  53.     {
  54.         int namber_of_files = bits;
  55.         int stlength = strlen(file_output);
  56.         strcat(file_output,"_0.txt");
  57.         stlength++;
  58.         int length_of_files = file_length / namber_of_files;
  59.         FILE *p = fopen(file_name, "rb");
  60.         for (int i = 0; i < namber_of_files; i++)
  61.         {   printf("%s", file_output);
  62.             file_output[stlength] = i + '0';
  63.             FILE *d = fopen(file_output, "wb");
  64.             for (int j = 0; j < length_of_files; j++)
  65.             {
  66.                 char k;
  67.                 if ((k = fgetc(p)) == EOF)
  68.                     return 0;
  69.                 fputc(k, d);
  70.             }
  71.             fclose(d);
  72.  
  73.  
  74.         }
  75.  
  76.     }
  77.     else
  78.     {
  79.         printf("You make a mistake, try again.");
  80.         return 0;
  81.     }
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement