Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String

Status
Not open for further replies.

JTan

Technical User
Oct 9, 2001
73
SG
May I know how to pass in a string parameter and to declare a string return-type?
 
try out this

#include <......> // header files as
#include <......> // required by
#include <......> // application

void main(void)
{char mystring[21];
int ret_value=0;
memset(mystring, 0, sizeof(mystring));

ret_value=Get_Input(mystring, column, row, length, .....other para)

{...
...
code to check return value
}
}


int Get_Input(char *txt,int col, int row,int length,int type)



the function Get_Input would have to be written explicitly by u to accept the character values and check the length. U can also set the row, column, foreground and background colors and any other validations if required.

 
use the return type as char*

char* function()
{
return &quot;hello&quot;;
} Ion Filipski
1c.bmp


filipski@excite.com
 
you may use char * as the data type for passing in returning a string, example:

char* func (char * a)
{
char b[5] = &quot;halo&quot;;

//codes are here

return b;
}
Andrew Lim

Trying and exploring is adventuring
 
I disagree with Andrew and Ion. You should never return a local (automatic) char* variable because the pointer is defined only for the function scope. At least, set the pointer returned by the function to static memory:


char * foo(void)
{
static char a[6] = &quot;hello&quot;;
return a;
}



Ion and Andrews code, for example, does not work on my machine.

Regards,
Ralf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top