c - How can I output my string array by passing reference in a function? -


when trying code in bellow has stopped.but why?

#include<stdio.h> void nameview(char* []);  int n, i, j;  int main(){     char name[10][10];      printf("enter case: ");     scanf("%d", &n);      for(i=0; i<n; ++i){         printf("enter name: ");         scanf("%s", name[i]);     }      nameview(&name);       return 0;  }    void nameview(char *b[]){     for(i=0; i<n; ++i){          printf("\n%s", *b[i]);     }  } 

programmed has stoped when replaced

    for(i=0; i<n; ++i){          printf("\n%s", *b[i]);     }  

insead of "nameview(&name)" in main function it's work.how can output passing reference in "nameview()" function

as mentioned in comments, function prototype:

void nameview(char* []); 

does not match definition:

void nameview(char *b){ 

additionally, argument pass in (&name `char (*)[10][10], i.e. pointer 2d array) doesn't match either parameter.

you need declare , define function take 2d array of 10x10 chars:

void nameview(char b[10][10]){ 

or equivalently, pointer array of size 10:

void nameview(char (*b)[10]){ 

and call name of array:

nameview(name); 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -