how do u return a string by value??
how do u return a string by value??
Declare the function to return a pointer to char, that way you can return the first element of the string.
-PreludeCode:char * function ( char * a ) { return a; }
My best code is written with the delete key.
but that does not return the value it returns a pointer to the value, which would not work if u are returning a local varible within the function
>but that does not return the value it returns a pointer to the value
Which is still returning by value, and the only way you can return a string in C. If you are returning a local variable, either declare the variable as static, allocate memory for it, or let the calling function send you a buffer to hold the string.
An alternative is to wrap the string in a structure and return that.
-PreludeCode:#include <stdio.h> typedef struct { char temp[BUFSIZ]; } WRAP; static WRAP returnString ( void ) { WRAP t = {"This is a string"}; return t; } int main ( void ) { WRAP ret; ret = returnString(); puts ( ret.temp ); return 0; }
My best code is written with the delete key.