Ok, so i've got a bit of a problem. I've dynamically allocated a 2d array, grabbeb input and put it into a buffer, and now would like to print the output, but am having some trouble thus far.
Here is my code:
** Note: the variable size included in the malloc statement is a previously defined variable by the user ** just incase anyone was wondering why it was there
Any help is greatly appreciatedCode:p = (char**)malloc(size*sizeof(char*)); if (p == NULL) merror(); for (j=0; j<size; j++) { p[j]=(char*)malloc(21); if (p[j] == NULL) merror(); B: printf("Enter a name:"); fflush(stdout); for(k=0; k<20; k++) { buffer[k]=fgetc(stdin); if (buffer[k]=='\n') { buffer[k]='\0'; break; } } if (k==20) { printf("input too long\n"); while(fgetc(stdin)!='\n'); goto B; } if (buffer[0]=='\0') { printf("Empty input. Please re-enter\n"); goto B; } } // Here is where i need to print the output of words // Not too sure how to do this i.e., what for statements, and how to strcpy from the buffer to array and print it } return 0; }