Basic encryption program that alters a file

  • Thread starter Nicholas Tilton
  • Start date

Nicholas Tilton

I have to create a program that takes the text inside of a file, converts all upper case letters to lower case, and shifts them 13 letters down in the alphabet. I have some code so far, but I'm stumped. What am I missing here? I think I'm confused about how to reprint the changed characters into the file after shifting them.

I'm very new to programming in c, so I don't know where to go from what I have here.

#include <ctype.h>
#include <stdio.h>

int getc( FILE argv[] ) ;

int main( int argc, char *argv[] ) {
FILE *fin, *fout ;
int c ;

fout = fopen( argv[1], "w" ) ;
fin = fopen( argv[1], "r" ) ;
c = getc( fin ) ;

while( ( c = getc( fin ) ) != EOF ) {
c = tolower( c ) + 13 ;
if( c > 127 ) c = c - 127 ;
fputc( c, fout ) ;

fclose( fin ) ;
return 0 ;

With this code, it will delete the contents of my text file given in argv[1] and will simply delete the contents of the text file. I don't get any error messages while compiling.

Continue reading...