爲什麼當我這樣做:Ç - 三元操作符
int ft_is_alpha(char *str, int i)
{
return (((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) ? 0 : 1);
}
它崩潰,但是,當我這樣做:
int ft_is_alpha(char *str, int i)
{
if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
{
return (1);
}
return (0);
}
它不會崩潰..
我調用這樣的功能
for (i = 0; str[i] != '\0'; ++i)
{
if (ft_is_equal_to(str, i))
{
++count;
int j;
j = i - 1;
while (str[++j] != '\0' && ft_is_alpha(str, j))
{
++length;
}
}
}
如果發生崩潰,可能是調用未定義的行爲。或者你的'我'超出了'障礙'範圍,或者問題在別處。 –
'我'是什麼?或者你如何調用這個函數? – Gopi
呼叫者正在崩潰嗎?由於你的兩個版本返回相反的結果。 –