gpt4 book ai didi

c - 我应该如何用指针算术来解决这个密码?

转载 作者:行者123 更新时间:2023-11-30 17:44:48 25 4
gpt4 key购买 nike

问题如下:

Solve the following cipher using Pointer Arithmetic. The given string is GKQTEHIN. Define a pointer and set it to the letter ‘T’ in this string. Traverse the string forward and backward. Add/subtract a single value (key) between 1 and 5 to each letter to solve this cipher and form a meaningful word. Hint: You will be using this as you solve it.

希望这已经正确完成......

char given[]="GKQTEHIN";
char *pointer;
pointer=&given[3];

pointer-=3;
printf("%c", *pointer-4);

pointer+=1;
printf("%c", *pointer+4);

pointer+=1;
printf("%c", *pointer-4);

pointer+=1;
printf("%c", *pointer-4);

pointer+=1;
printf("%c", *pointer+4);

pointer+=1;
printf("%c", *pointer+4);

pointer+=1;
printf("%c", *pointer-4);

pointer+=1;
printf("%c\n\n", *pointer+4);

打印出“COMPILER”一词。

最佳答案

How do I "add/subtract a single value...to each alphabet"?

计算机只能理解和处理数字,因为计算机中的一切都是数字(或可以被视为数字)。这意味着字母内部实际上是数字。 C 中的 char 使用 ASCII encoding ,这使得每个字母对应一个数字。因此,您只需将 key 添加到表示该 char 的代码中即可。您可以毫无问题地使用 char 作为数字。

char a = 'a';
a++;
printf("%c\n", a); // prints 'b'

关于c - 我应该如何用指针算术来解决这个密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19839068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com