推 da0910cc:OO static代表兩個function"共同"修改某個變數 12/16 09:29
非常感謝!!!
※ 編輯: jim055006 來自: 223.142.237.142 (12/16 23:10)
Please define what a re-entrant function is. The following function,
strToLower(), accepts one character pointer and translates all characters in the
string into lower characters. The implementation in NOT a re-entrant function.
Please correct the code so it becomes a re-entrant function.
Char *strToLower(char *str)
{
static char buffer[STRING_SIZE_LIMIT];
int index;
for(index=0;str[index];index++)
buffer[index] = tolower(str[index]);
buffer[index] = "\0";
return buffer;
}
答案是
Char *strToLower(char *str)
{
char buffer[STRING_SIZE_LIMIT];
int index;
for(index=0;str[index];index++)
buffer[index] = tolower(str[index]);
buffer[index] = "\0";
return buffer;
}
就只是把static刪掉就變成reentrant code??
為什麼呢??
那個static的作用是啥??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 223.140.227.136