bogdan2004333

Untitled

Nov 13th, 2022 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <string.h>
  4. #include "caesar.h"
  5.  
  6. void string(FILE *a, const int *len, char *arr) {
  7.     fseek(a, 0, SEEK_END);
  8.     int lenght = ftell(a);
  9.     fseek(a, 0, SEEK_SET);
  10.     int i = 0;
  11.     while (!feof(a) && i < lenght && i < *len) {
  12.         *(arr + (i++)) = getc(a);
  13.         *(arr + i) = 0;
  14.     }
  15. }
  16.  
  17. int main() {
  18.     setlocale(0, "");
  19.     const int len = 1024;
  20.     char line_source[len];
  21.     char line_key[len];
  22.     int len_code[len];
  23.     const char *delims = "."",!? /<>|)(*::-\n";
  24.  
  25.  
  26.     FILE *source = fopen("source.txt", "r");
  27.     FILE *key = fopen("key.txt", "r");
  28.     FILE *code = fopen("code.txt", "w");
  29.     if (!code) {
  30.         printf("Не удалось открыть закодированный текст!");
  31.     }
  32.     if (!source) {
  33.         printf("Не удалось открыть основный текст!\n");
  34.         return 1;
  35.     }
  36.     if (!key) {
  37.         printf("Не удалось открыть кодовый блокнот!\n");
  38.     }
  39.     string(source, &len, line_source);
  40.     string(key, &len, line_key);
  41.     char *token;
  42.     int n = 0;
  43.     int j = 0;
  44.     int i = 0;
  45.     token = strtok(line_key, delims);
  46.     while (token != NULL) {
  47.         if(line_key[j]!=NULL) {
  48.             n += (int) line_key[j];
  49.             j++;
  50.  
  51.         } else {
  52.             len_code[i] = n;
  53.             printf("%d\n", len_code[i]);
  54.             i++;
  55.             n = 0;
  56.             j++;
  57.             token = strtok(NULL, delims);
  58.         }
  59.  
  60.     }
  61.  
  62.  
  63.     fclose(code);
  64.     fclose(source);
  65.     fclose(key);
  66.     return 0;
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment