0
在這個凱撒密碼我如何讓它讀取空格,特殊字符(!@#$ * ...)和數字,並保持它們原樣打印出來?另外我在fgets while循環的末尾放了一個fprintf(file2,「\ n」),它確實開始一個新行,但它總是在前一行的末尾打印出一個奇怪的字符。凱撒密碼在C
#include <stdio.h>
int main (int argc, char *argv[]) {
char caesar[256];
int shift;
FILE *file1=fopen(argv[1],"r");
FILE *file2=fopen(argv[2],"w");
sscanf(argv[3], "%d", &shift);
while(fgets(caesar,sizeof(caesar),file1)!=NULL){
int i = 0;
while (caesar[i] != '\0') {
if (((caesar[i] + shift) >= 65 && (caesar[i] + shift) <= 90)||((caesar[i] + shift) >= 97 && (caesar[i] + shift) <= 122)) {
caesar[i] += (shift);
}
else {
caesar[i] += (shift - 26);
}
i++;
}
fprintf(file2,"%s", caesar);
fprintf(file2,"\n");
}
return 0;
}
難道沒有做到這一點OP。 – leppie