well I still canīt see why this programm wont work
Code:
#include <stdio.h>
#include <stdlib.h.>
FILE *fp;
int main (void)
{
int code, key, xy, c;
printf("Enter 1 OR -1:");
scanf("%d",&code);
printf("\nEnter Key-->");
scanf("%d",&key);
fp=fopen("message.txt","r"); /*read file, show on screen*/
if(fp==NULL)
{
printf("\nFile does not exist\n");
exit(EXIT_FAILURE);
}
else
{
do
{
c=fgetc(fp);
putchar(c);
}while(c!=EOF);
}
printf("\n");
fclose(fp);
fp=fopen("message.txt","r+"); /*read file and write encrypted file*/
do
{
c=fgetc(fp);
xy=(c+key*code)%256;
fputc(xy, fp);
}while(c!=EOF);
fclose(fp);
return 0;
}
I replaced Salems code
Code:
int ch;
while ( (ch=fgetc(fp)) != EOF ) {
xy=(ch+1)%256;
fseek( fp, -1, SEEK_CUR ); // step back a char
fputc(xy, fp);
}
and I get an endless loop which made the opened file really big