2015-05-04 43 views
2

我與C中的strcat功能有點問題,我要的是,有一個字符串(org_surname),檢查選擇的字符是一個輔音,並將其添加到另一個字符串(coded_surname)。Ç - 字符串錯誤

int lenght = strlen(org_surname); int i = 0; int count = 0; 

while(i<lenght && count < 3){ 
    if (org_surname[i] != 'a' && org_surname[i] != 'e' && org_surname[i] != 'i' && org_surname[i] != 'i' && org_surname[i] != 'u'){ 
     strcat(coded_surname,org_surname[i]); 
     count++; 
    } 
    i++; 
} 

錯誤總是相同的。

"passing argoment 2 of strcat makes a from integer without a cast. 

我該如何解決這個問題?

回答

2

錯誤是永遠不變的。 「路過的strcat的argoment 2使得從整數沒有投。

那是因爲你是路過org_surname[i]strcat。第二個參數strcat需要是一個字符串,一個char const*,不是char

您可以使用:

len = strlen(coded_surname); 
coded_surname[len] = org_surname[i]; 
coded_surname[len+1] = '\0';