Je sais que nous sommes en mesure de changer une chaîne grâce à une fonction comme celui-ciComment modifier un tableau 2D passé à une fonction
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);
}
Dans ce cas, il imprimera « sssss ». Mais comment puis-je modifier un tableau 2d de la même façon que pour une chaîne? Je veux dire sans retourner le tableau.
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);
}
Voici une idée de comment nous pourrions le faire.
J'espère avoir été assez clair?
Comment puis-je appeler la fonction? J'ai essayé func (s) mais ça ne marche pas :( – Beben
Merci pour votre réponse! :) – Beben