Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <locale.h>
- #include <string.h>
- #include "caesar.h"
- void string(FILE *a, const int *len, char *arr) {
- fseek(a, 0, SEEK_END);
- int lenght = ftell(a);
- fseek(a, 0, SEEK_SET);
- int i = 0;
- while (!feof(a) && i < lenght && i < *len) {
- *(arr + (i++)) = getc(a);
- *(arr + i) = 0;
- }
- }
- int main() {
- setlocale(0, "");
- const int len = 1024;
- char line_source[len];
- char line_key[len];
- int len_code[len];
- const char *delims = "."",!? /<>|)(*::-\n";
- FILE *source = fopen("source.txt", "r");
- FILE *key = fopen("key.txt", "r");
- FILE *code = fopen("code.txt", "w");
- if (!code) {
- printf("Не удалось открыть закодированный текст!");
- }
- if (!source) {
- printf("Не удалось открыть основный текст!\n");
- return 1;
- }
- if (!key) {
- printf("Не удалось открыть кодовый блокнот!\n");
- }
- string(source, &len, line_source);
- string(key, &len, line_key);
- char *token;
- int n = 0;
- int j = 0;
- int i = 0;
- token = strtok(line_key, delims);
- while (token != NULL) {
- if(line_key[j]!=NULL) {
- n += (int) line_key[j];
- j++;
- } else {
- len_code[i] = n;
- printf("%d\n", len_code[i]);
- i++;
- n = 0;
- j++;
- token = strtok(NULL, delims);
- }
- }
- fclose(code);
- fclose(source);
- fclose(key);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment