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 - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

java - Reading data from multiple zip files and combining them to one -