STRING
pass char[][]
to function
-
function to read char[][]
2D
void readMatrix( char *matrix[][cols]) {
matrix[i][j] = "aaa";
}
char *mat[rows][cols];
readMatrix(mat);
- with maloc and pointer
void readMatrix(char**** matrix){
*matrix = malloc(rowNum*sizeof(char**));
for(int i=0;i<rowNum;i++){
*(*matrix+i) = malloc(columnNum*sizeof(char*));
}
*(*(*matrix+i)+j) = malloc(MAX_WORD_SIZE*sizeof(char));
scanf("%s",*(*(*matrix+i)+j));
}
char*** inputMatrix;
readMatrix(&inputMatrix);
printf("%s ",*(*(inputMatrix+i)+j));
Read string with white space from file with fscanf
char s[40];
fscanf (fp, "%d,%f,%[a-zA-Z ]\n", &i, &x, s);