我想了解这个特定的代码行。了解字符串数组c
我无法理解为什么需要3个赋值语句。我认为这是最低限度的必要条件,我似乎无法用我的想法跟随它。
如果有人可以带我通过这个每一行,用英语,这将是太棒了。
谢谢。
void to_upper(char *word) {
int index = 0;
while (word[index] != '\0') {
word[index] = toupper(word[index]);
index++;
}
}
int length(char *word) {
int index=0;
while (word[index] != '\0')
index++;
return index;
}
void reverse(char *word) {
int index, len;
char temp;
len = length(word);
for (index=0; index<len/2; index++) {
temp = word[index];
word[index] = word[len-1-index];
word[len-1-index] = temp;
}
}
这不仅仅是一行代码。究竟你对什么部分感到困惑?假设你问的是“反向”,你将如何用更少的任务来完成它? – jamesdlin 2013-02-19 02:28:07
'to_upper'和'length'并不是你询问的内容,是吗? – singpolyma 2013-02-19 02:28:47
为什么你有自定义的'length'而不是只使用'strlen'? – singpolyma 2013-02-19 02:29:06