1

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';     
};

will result in segmentation fault. i pass a array of character pointers that was initialized as follow

char argv[ARG_NUM][MAX_LINE];

trying to figure out the cause,but with not success

what might be the issuse?

naor.z
  • 107
  • 8

2 Answers2

1

That's how you should pass it to the function because it isn't a char **. You have to delete the ; after the curly bracket.

/*Dim is your ARG_NUM and dim2 MAX_LINE*/
int fetchargs(int dim1,int dim2,char pass[][MAX_LINE]){
    /*Some stuff*/
    return 1;
}/*You've a semicolon here*/
simo-r
  • 733
  • 1
  • 9
  • 13
1

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;  
};
Zakir
  • 2,222
  • 21
  • 31