I am new to C, I can't seem to find much on pointer pointer char for the purpose that I need it. Here's my code simplified:
int total, tempX = 0;
printf("Input total people:\n");fflush(stdout);
scanf("%d",&total);
char **nAmer = (char**) malloc(total* sizeof(char));
double *nUmer = (double*) malloc(total* sizeof(double));;
printf("input their name and number:\n");fflush(stdout);
for (tempX = 0;tempX < total; tempX++){
scanf("%20s %lf", *nAmer + tempX, nUmer + tempX); //I know it's (either) this
}
printf("Let me read that back:\n");
for (tempX = 0; tempX < total; tempX++){
printf("Name: %s Number: %lf\n",*(nAmer + tempX), *(nUmer + tempX)); //andor this
}
I'm not sure what the proper format for pointer pointer char when getting user input. As you can see, I'm trying to get a list of people's name along with their number. I know Arrays, Matrices, and stuff like that is easy, but it has to be a pointer pointer only. Thanks!
If you want to store N strings of up to 20 characters each, you need to allocate not just the space for the pointers-to-the-strings, but the also the space to hold the strings themselves. Here's an example: