I am a beginner in C and I want to know how declare function which returns a string. I have tried to create but normally it gives me a segmentation stack run time error. Thank you to those who would explain to me ..
Printable View
I am a beginner in C and I want to know how declare function which returns a string. I have tried to create but normally it gives me a segmentation stack run time error. Thank you to those who would explain to me ..
Code:# include <stdio.h>
char * function () (
char * str = "test";
return str;
)
int main () (
printf ( "% s \ n", function ());
return 0;
)
In the C API, certain functions return a string as a parameter. Each of these functions uses the same interface for retrieving a string. msStringProperty() is a pointer to a buffer provided by the application into which XMS copies the characters in the string.
To return string from a function try this program :
ex:Code:
#include
char * cfun(void);
main ()
{
printf("%s\n",cfun());
}
char * cfun(void)
{
char *name;
name = (char *)malloc(20*sizeof(char));
printf("Enter name\n");
scanf("%s",nme);
return(nme);
}