I need to rename the file, but I do not understand what is wrong, the file is encrypted, but the name does not change, how to use the rename () function correctly. I need to change the file name to "encrypt.yes"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char new[20];
char old[20];
int rename(const char *old, const char *new);
int ch;
FILE *fps;
printf("Enter file name (with extension like file.txt) to encrypt : ");
strcpy(new,"encrypt.yes");
rename(old, new);
scanf("%s", old);
fps = fopen(old, "r+");
if (fps == NULL) {
printf("Could not open file '%s'\n", old);
return 1;
}
while ((ch = fgetc(fps)) != EOF) {
ch += 100;
fseek(fps, -1, SEEK_CUR);
fputc(ch, fps);
fseek(fps, 0, SEEK_CUR);
}
fclose(fps);
printf("File '%s' encrypted successfully\n", old);
return 0;
}