hi. I am trying to write a program that changes each character in a text file by moving each character along a by a set number in the alphabet but am completely stuck. I have done the program that reads in a text file and writes one out but I dont now how to do the bit in the middle where each character gets shifted along between 1 and 26 spaces? how can I convert each letter in the alphabet to a number? what variables do I need? any help greatly appreciated!
here is my code so far:
Code:
#include <stdlib.h>
#include <stdio.h>
#include < string.h >
//a program that reads in a text file chosen by the user character by character and writes it to a new file (I got stuck on the offset key bit) 16.12.10
void main ()//defines a program called main
{
FILE *file_in;//defines the stream as file in
FILE *file_out;//defines a stream as file out
char letter, destination[30]; //defines a string for each character and and array for the name of the text file
int offset = 0;
printf("please enter the off set key amount\n");
printf("please enter the file destination you want to read in\n");//gets the user to enter a file
scanf("%s%d" , destination , offset);//reads in the destination and stores it in destination variable
file_in=fopen(destination, "r");// opens and reads the file
file_out=fopen("newtest.txt", "w");
do//reads in the file and prints the file untill the end of file condition is met.
{
letter=getc(file_in);//reads each letter in one at a time to the letter variable
fprintf(file_out, "%c" , letter);//prints each letter out on the screen
}
while
(letter != EOF);//checks if has reached the end of the text file
fclose(file_in);
fclose(file_out);//closes the stream
}