c - Array of pointers to char check for new string -


i have array of pointers chars store string console. how can check, if new string entered inkrement index? thought segmentation fault.

char** arr; int = 0; int j = 0;  arr = malloc(sizeof(char*) * 10);  while (arr[i][j] != '\n') {     scanf("%c", &arr[i][j]);     j++; } i++; // read next string here 

you allocating memory pointers. need make pointers point memory location before writing it.like

arr[i] = malloc(sizeof(char) *20); 

Comments

Popular posts from this blog

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -