Шифрование кодом Цезаря. Как сделать бесконечное шифрование, выдает ошибку памяти после первой итерации цикла?

#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>         
        
int main(){            
    char folder_path[10000];
    scanf("%s", folder_path);
    DIR* dir;
    dir = opendir(folder_path);
    int shift;
    scanf("%d", &shift);
    if (dir != NULL) {
        struct dirent* ent;  
        char c_files[] = ".c";
        while ((ent = readdir(dir)) != NULL) {
            if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) {
                char file_path[12000];
                sprintf(file_path, "%s/%s", folder_path, ent->d_name);
                if (strstr(file_path, c_files) != NULL) {
                    while (1) {
                        shift++;
                        FILE* text1 = fopen(file_path, "r+");
                        char c;
                        c = getc(text1);
                        while (!feof(text1)) {
                            if (c >= 'A' && c <= 'Z') {
                                c = ((c - 'A' + shift) % 26 + 'A');
                                fseek(text1, -1L, SEEK_CUR);
                                fprintf(text1, "%c", c);
                                fflush(text1);
                                c = fgetc(text1);
                            } else if (c >= 'a' && c <= 'z') {
                                c = ((c - 'a' + shift) % 26 + 'a');
                                fseek(text1, -1L, SEEK_CUR);
                                fprintf(text1, "%c", c);
                                fflush(text1);
                                c = fgetc(text1);
                            } else if (c >= '0' && c <= '9') {
                                c = ((c - '0' + shift) % 26 + '0');
                                fseek(text1, -1L, SEEK_CUR);
                                fprintf(text1, "%c", c);
                                fflush(text1);
                                c = fgetc(text1);
                            } else {
                                c = fgetc(text1);
                            }
                        }
                    fclose(text1);
                    }
                }
            }
        }
    closedir(dir);
    }
}

Ответы (0 шт):