I've got the following piece of code. I got a pointer from the function and keep it in array of char pointers. Everything looks OK however when I try to print from main function array[0] it prints some symbols but not what I need. I use now memory allocation in the function as advised however still not there
Many thanks
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *getIn();
int main(void)
{
char *array[3];
array[0] = getIn();
array[1] = getIn();
array[2] = getIn();
printf("%s\n", array[0]);
return 0;
}
char* getIn()
{
char *p;
char input[30];
printf("Please enter something: ");
fgets(input, 20, stdin);
input[strlen(input) - 1] = '\0';
p = (char *) malloc(sizeof(char));
p = input;
return p;
}