Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)
void reverse(char* str){
if(str==NULL)
return;
int i=0,j=strlen(str)-1;
while(i<j){
int tmp=str[i];
str[i]=str[j];
str[j]=tmp;
//forget i++,j-- when writing on paper
i++;
j--;
}
}
在紙上,看似簡單的代碼還是總出問題:我忘記了i++,j--,將紙上的程序輸入到計算機中時導致死循環