I need to write a program that asks the user for the text file, prints its contents, then asks for the output file, encrypts the contents of the first file with caeser cipher and writes the encryption to the output file. So far I have this code, it writes the contents of the file, asks for the output file, and offset key, it has no errors or trouble compiling but after I run it the output file is still empty!
Code:
#include<stdio.h>
#include<stdlib.h>
#include <ctype.h>


int encode (int, int);


int encode(int ch, int key) { 
    if (islower(ch)) {
         ch = (ch-'a' + key) % 26 + 'a';
         ch += (ch < 'a') ? 26 : 0;
    }
    else if (isupper(ch)) {
         ch = (ch-'A' + key) % 26 + 'A';
         ch += (ch < 'A') ? 26 : 0;
    }
    return ch;
}
int main (void) 
{
    FILE *file_in;
    FILE *file_out;
    char ch;
    char text[300];
    int key;


    printf("Enter the name of the file you wish to see including complete pathway and file\n extension:\n");
    gets(text);
    file_in = fopen(text,"r"); 


    if( file_in == NULL )
    {
       perror("Error while opening the file.\n");
       exit(EXIT_FAILURE);
    }
       printf("\n The contents of the file are : \n");
    
    while( ( ch = fgetc(file_in) ) != EOF )
    {
       printf("%c",ch);
    }


    printf("\n \n Enter the name of the file you wish to send the encryption\n to including complete pathway and file\n extension:\n");
    gets(text);
    file_out = fopen(text,"w");
    
    printf("\n Enter the alphabetic offset key you would like to use:");
    scanf("%d", &key);
    
    while( ( ch = fgetc(file_in) ) != EOF )
    { 
        encode(ch, key);
        fprintf(file_out, "%c", ch);
    }
    printf("file has been encoded");
    fclose(file_out);
    fclose(file_in);
    
    return 0;
}