我正在尝试逐行浏览文件(每行不超过 50 个字符),将每个字符移动 10 或 -10(加密和解密),然后在旧字符串所在的位置打印移动后的字符串。但我得到了一些非常有趣的输出。
继承人的代码:
#include <stdio.h>
int main(void){
FILE *fp;
fp=fopen("tester.csv","r+");
Encrypt(fp); // I call decrypt here when I test it.
fclose(fp);
}
int Encrypt(FILE *fp){
int offset=10;
Shift(fp, offset);
}
int Decrypt(FILE *fp){
int offset= -10;
Shift(fp, offset);
}
int Shift(FILE *fp, int offset){
char line[50],tmp[50], character;
long position;
int i;
position = ftell(fp);
while(fgets(line,50,fp) != NULL){
for(i=0;i<50;i++){
character = line[i];
character = (character+offset)%256;
tmp[i] = character;
}
fseek(fp,position,SEEK_SET);
fputs(tmp, fp);
position = ftell(fp);
}
}
所以如果 tester.csv 最初读取
this, is, a, test
运行程序产生
~rs}6*s}6*k6*~o}~
êñv[ ‰
this, is, a, test