Segmantation fault when trying to access array of character pointers

后端 未结 2 1619
不知归路
不知归路 2021-01-24 10:15

so i\'ve created a function that deals with a array of char pointers by using the [] operators. the function

int fetchargs(char **argv){
argv[0][0] = \'A\';              


        
2条回答
  •  失恋的感觉
    2021-01-24 10:34

    char ** argv is a pointer to a pointer of character(s) or a double pointer
    Where as argv[ARG_NUM][MAX_LINE] is essentially a 2D array of characters

    Bottom line here is to Honor the Data Types

    char argv[ARG_NUM][MAX_LINE];
    .........
    .........
    int fetchargs(char argv[][MAX_LINE]){
      argv[0][0] = 'A'; 
      return 0;  
    };
    

提交回复
热议问题