,我知道我們能串多虧改變這樣的函數如何修改傳遞給函數
void c(char *s)
{
int i = 0;
while (s[i])
s[i++] = 's';
}
int main()
{
char str[] = "hello";
c(str);
printf("%s\n", str);
return (0);
}
在這種情況下,將打印「SSSSS」一個二維數組。
但我怎麼能修改一個二維數組,就像我爲一個字符串一樣? 我的意思是不返回數組。
void c(char **s)
{
int i = 0;
int j = 0;
while (s[i])
{
j = 0;
while (s[i][j])
{
s[i][j++] = 's';
}
i++;
}
}
int main()
{
char tab[2][2];
tab[0][0] = 'a';
tab[0][1] = 'b';
tab[1][0] = 'c';
tab[1][1] = 'd';
c(tab);
printf("%c%c\n%c%c", tab[0][0], tab[0][1], tab[1][0], tab[1][1]);
return (0);
}
下面是我們如何做到這一點的想法。
我希望我已經清楚了嗎?
如何調用該函數?我嘗試過func(s),但它不起作用:( – Beben
謝謝你的回覆!:) – Beben