2013-04-09 130 views
1
int isPurePalindrome(const char *sentence){ 
int i;  
if (sentence="")  
return 0; 
char *begin; char *end; i=strlen(sentence);//i is now the length of sentence string 
*begin= &sentence(0); 
*end=&sentence[i-1]; 

我正在使用dev C++。我試圖初始化指針「開始」指向字符串「句子」中的第一個字符,但它不斷給我一個錯誤,「賦值使指針沒有轉換指針的整數」。 「*句子」指向用戶在主文件中輸入的字符串。 ispalindrome是一種寫作功能。假設在main中輸入的句子是NULL,則返回0。使用指向字符串的指針初始化指向字符串中的字符的指針

+0

基本上你不會能夠編譯這個code.compiler投訴字符串比較。並刪除後代碼應編制在'C99'標準 – 2013-04-09 05:01:01

回答

3

有你的代碼的幾個問題:

if (sentence="") return 0; 

應該

if (strcmp(sentence,"")==0) return 0; 

char *begin; char *end; 

應該

const char *begin; const char *end; 

*begin= &sentence(0); 

應該

begin = &sentence[0]; 

*end=&sentence[i-1]; 

應該

end = &sentence[i-1]; 
+0

也許你還可以提及關於混合聲明和身體與標準 – 2013-04-09 05:02:04

+0

@Vaughn Cato非常感謝。有效!!! – user2260097 2013-04-09 17:16:43

0

有一堆代碼中的問題,但在導致該錯誤信息是,當你不需要時,你正在解引用。你想:

begin = &sentence[0]; 
end = &sentence[i-1]; 
0
begin = &sentence[0]; 
end = &sentence[i - 1]; 

這將解決你的問題..

-1

你應該寫[]

*begin= &sentence(0); 
insted的的 ()

你應該種姓句子(字符*)之前分配它開始和結束。

*begin = ((char*)sentence)[0]; 

*end = ((char*)sentence)[i -1]; 
+0

施法只隱藏錯誤而不是修復它 – anatolyg 2013-04-09 06:08:11