There are two major annoyances in your code.
1 - incorrect memory allocation. The string in C is a pointer to an array. Those. an array of strings is an array of pointers to arrays . Below I give the corrected code, I think everything will become clearer. Accordingly, a pointer to it is necessary to transfer to scanf for a string, which in our case (an array of pointers to arrays of characters ) is simply a pointer to an array of characters, i.e. just name[i] or just user[i] .
2 - %s reads everything up to a space, so what do you have when you type, say,
aa,1,bb
as the first line of the name this will all be read. In general, it is considered to be a good form to check what the input function returns ... The easiest way is to request separation by spaces; if this does not suit you - see in the documentation how you can modify the %s format specifier to do what you want. I used spaces for simplicity.
int main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); int num; //ΡΠ°Π·ΠΌΠ΅Ρ ΠΌΠ°ΡΡΠΈΠ²Π° int i = 0; int* index;//Π£ΠΊΠ°Π·Π°ΡΠ΅Π»ΠΈ Π½Π° ΠΌΠ°ΡΡΠΈΠ²Ρ Ρ Π΄Π°Π½Π½ΡΠΌΠΈ char** user; char** name; const int len = 40; // length of string printf("Π-Π²ΠΎ ?"); scanf("%d", &num); printf("ΠΠ²Π΅Π΄ΠΈΡΠ΅: Π’Π΅ΠΊΡΡ ΡΠΈΡΠ»ΠΎ ΡΠ΅ΠΊΡΡ\n"); //Π΄ΠΈΠ½Π°ΠΌΠΈΡΠ΅ΡΠΊΠΎΠ΅ Π²ΡΠ΄Π΅Π»Π΅Π½ΠΈΠ΅ ΠΏΠ°ΠΌΡΡΠΈ index = (int*) malloc(num * sizeof(int)); user = (char**) malloc(num * sizeof(char*)); name = (char**) malloc(num * sizeof(char*)); for (i = 0; i < num; ++i) { user[i] = (char*) malloc(len); name[i] = (char*) malloc(len); } for (i = 0; i < num; i++) { if (scanf("%s %d %s", name[i], &index[i], user[i]) != 3) printf("Wrong input\n"); } printf("%s", user[0]); for (i = 0; i < num; ++i) { free(user[i]); free(name[i]); } free(index); free(user); free(name); return 0; }