I need to input some string in function with prototype char* () and print that string in main function but I can menage to do that. I'm a begginer in c programing.
I try this:
#include <stdio.h>
#include <stdlib.h>
char* read_data();
int main()
{
char str[100];
char *p_str;
p_str=read_data();
printf("entered string is: %s and pointer on that string is %p \n",p_str,p_str);
//print from here is a problem. Pointer is nicesly pass to main function but it seems that string information are lost...
return 0;
}
char* read_data()
{
char str1[100];
char *p_str1;
p_str1=(char*)malloc(100*sizeof(char));
gets(str1);
p_str1=str1;
printf("entered string is: %s and pointer on that string is %p \n",p_str1,p_str1);
//print from here is not a problem - works fine
return p_str1;
}