Reputation: 716
How to use function in C with array of strings? My code:
void test(char **a){
printf("%s", a[0]);
}
int main(){
char b[10][10];
strcpy(b[0],"abc");
strcpy(b[1],"dfgd");
test(b);
return 0;
}
How to make this example of code work?
Upvotes: 1
Views: 101
Reputation: 3800
You can use :
void test(char a[10][10]){
printf("%s", a[0]);
}
or
void test(char a[][10]){
printf("%s", a[0]);
}
or
void test(char (*a)[10]){
printf("%s", a[0]);
}
int main(){
char b[10][10];
strcpy(b[0],"abc");
strcpy(b[1],"dfgd");
test(b);
return 0;
}
All three declarations are perfectly equivalent. Although last one is better.
This answer explains it better
Upvotes: 4