本文介绍了为什么这样做? (rot13功能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这是我写的一个小功能,灵感来自线程

紧急帮助!需要Caesar Cipher PLEASE


$ cat /home/keisar/bin/c/ymse/rot13.h

char rot13(char字符)

{

int change;

changed = character - ''a''+''n'';

返回已更改;

}


我发现此代码有两个奇怪之处:
1)我不知道不必指定b应该被替换为n,

c by o等等。怎么样?

2)该函数返回一个char(char rot13),但是改变了

是一个整数。怎么可能?

This is a little function I wrote, inspired by the thread
"Urgent HELP! required for Caesar Cipher PLEASE"

$ cat /home/keisar/bin/c/ymse/rot13.h

char rot13(char character)
{
int changed;
changed = character - ''a'' + ''n'';
return changed;
}

I find two things strange about this code:
1) I don''t have to specify that b should be replaced by n,
c by o and so on. How come?
2) The function returns a char(char rot13), but changed
is an integer. How is that possible?

推荐答案






因为字符是整数类型。与Pascal不同,C不需要

字符之间的转换函数及其数值,

但是将它们视为可互换的。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰----- --- \

\ - ---------------------规则! -------- /

给我看一个好的mouser,我会告诉你一只口臭的猫。

- 加菲猫



Because chars are integer types. Unlike Pascal, C does not require
conversion functions between characters and their numeric values,
but treats them as interchangable by themselves.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Show me a good mouser and I''ll show you a cat with bad breath."
- Garfield


这篇关于为什么这样做? (rot13功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:06