Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- int main(int argc, char ** argv)
- {
- char file_name[128];
- strcpy(file_name, argv[1]);
- FILE *p = fopen(file_name, "rb");
- char c;
- struct stat st;
- stat(argv[1], &st);
- int file_length = st.st_size;
- fclose(p);
- char action;
- action = argv[2][0];
- int bits = atoi(argv[3]);
- char file_output[128];
- strcpy(file_output, argv[4]);
- if (action == 's')
- {
- int length = strlen(file_output);
- strcat(file_output,"_0.txt");
- length++;
- int n = file_length / bits;
- FILE *p = fopen(file_name, "rb");
- for (int i = 0; i < n; i++)
- {
- file_output[length] = i + '0';
- printf("%s", file_output);
- FILE *d = fopen(file_output, "wb");
- for (int j = 0; j < bits; j++)
- {
- char k;
- if ((k = fgetc(p)) == EOF)
- return 0;
- fputc(k, d);
- }
- fclose(d);
- }
- }
- else if (action == 'n')
- {
- int namber_of_files = bits;
- int stlength = strlen(file_output);
- strcat(file_output,"_0.txt");
- stlength++;
- int length_of_files = file_length / namber_of_files;
- FILE *p = fopen(file_name, "rb");
- for (int i = 0; i < namber_of_files; i++)
- { printf("%s", file_output);
- file_output[stlength] = i + '0';
- FILE *d = fopen(file_output, "wb");
- for (int j = 0; j < length_of_files; j++)
- {
- char k;
- if ((k = fgetc(p)) == EOF)
- return 0;
- fputc(k, d);
- }
- fclose(d);
- }
- }
- else
- {
- printf("You make a mistake, try again.");
- return 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement