I want to use an array of string the same as this:
char arr[][20] = {"username1", "username2"};
after i have not problem to get values, for example :
printf("%s", arr[0]); // for "username1"
i have problem to insert new string to this array, something like this!? :
arr[2] = "username3"; // or sprintf(arr[2], "%s", "username3");
The wrong way of doing this would be as follows:
because, when you write something like the below
The first dimension is automatically calculated based on the given initializer, in this case, it is
2(i.e. index0and1).Later when you try to access (read or write), the third element i.e. index
2, it is a undefined behavior.If you want to increase the first dimension of a 2d array, the correct way of doing that would be as follows:
Hope this helps!