我寫了下面的函數用於從string..For前刪除重複的字符:如果 海峽=「heeello; removeDuplicate(STR)C程序...顯示運行時錯誤
將返回直升機...但它顯示了運行時的一些錯誤。我增加了一些的printf()語句進行調試......誰能告訴我是什麼問題?
char* removeDuplicate(char str[])//remove duplicate characters from a string,so that each character in a string is not repeating
{
int i = 0,j;
char ch;
printf("\nstr is %s",str);
while((ch = str[i++])!= '\0')
{
j = i;
printf("\n----ch = %c----",ch);
while(str[j] != '\0')
{
printf("\n--------Checking whether %c = %c \n",str[j],ch);
if(ch == str[j])
{
printf("\n------------Yes");
while(str[j]!='\0')
{
printf("\nRemoving %c %d -- \n",str[j]);
str[j] = str[++j];
--i;
}
break;
}
printf("\n------------No");
//printf("\njj");
j++;
}
}
return str;
}
你可以顯示你對這個函數的調用嗎? – MByD 2012-03-12 10:34:59
removeDuplicate(「heee」); – 2012-03-12 10:37:12
是的,這是呼叫問題... heee沒有\ 0:P ..是它的問題嗎? – 2012-03-12 10:39:30