c - 为 Ceasar's Code 在 C 中环绕

标签 c arrays file word-wrap

嘿,伙计,我上次发帖有点草率。希望这次看起来会好很多。如果您决定帮助我,谢谢您的宝贵时间。我真的需要它。无论如何,这是问题。我需要为我的代码环绕,我听说你可以用模数来做,但我不确定我做的是否正确,因为我没有得到正确的结果。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main () {
   char s[200]; //blank array//
   int mess;
   printf("Generations have wondered how the Ceasar Code works\n");
   printf("Please choose a number to mess up (encode) the current file\n");
   scanf("%d", &mess);
   mess = mess % 26;
   FILE *ptof = fopen("Rock.txt", "r");
   char a[200];//fill array with characters from file//
   int i=0;
   while( (a[i++]=fgetc(ptof)) != EOF && i < 89) { //get character from file//
   }
   a[i] = '\0'; /* null-terminate the string */
   i = 0;

   do{
      printf("%c",a[i++]);
   } while  (a[i] != '\0'); /* print until hit \0 */
   int j = 0;
   for (j = 0; j < 89; j++){
      s[j] = a[j] + mess;
   }
   printf("%s\n", s);

   fclose(ptof);
   return 0;
}

最佳答案

s[j] = a[j] + mess 也需要模运算

关于c - 为 Ceasar's Code 在 C 中环绕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24439672/

相关文章:

C "#define"函数名生成

c++ - 从(开放的)Solaris 交叉编译到 Windows?

java - 将文本文件打印到java中的特定打印机

php glob - 在子文件夹中扫描文件

计算 char Sir2 在序列 Sir1[] 中出现的次数

python - 将 Python 翻译成 C

javascript - 订购 key :value pairs of objects

如果文件已经存在(在写入模式下),fopen 会失败吗?

javascript - 如何从动态表单中获取值,将它们传递给变量并使用 JavaScript 中的查询字符串参数重定向到 URL?

javascript - 使用纯 JavaScript 基于搜索文本匹配的数组排序