I need to allocate arrays of chars by malloc()
and then print them.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (void){
int i, n, l;
char **p;
char bufor[100];
printf("Number of strings: ");
scanf("%d", &n);
p=(char**)malloc(n*sizeof(char*));
getchar();
for (i=0; i<n; ++i){
printf("Enter %d. string: ", i+1);
fgets(bufor, 100, stdin);
l=strlen(bufor)+1;
*p=(char*)malloc(l*sizeof(char));
strcpy(*p, bufor);
}
for (i=0; i<n; ++i){
printf("%d. string is: %s", i+1, *(p+i));
}
return 0;
}
I have a problem with printing those strings. I don't know how to get them.