我想了解這個特定的代碼行。瞭解字符串數組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