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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ANSI-C function prototype help 1

Status
Not open for further replies.

smartsarath2003

Programmer
Feb 8, 2006
1
GB
Hai,
I am trying to implement the fallowing code.But I am getting only one letter output "H". Its just trying to return a string from a function, but I think the problem is with function prototype declaration to return a srting value.
Can any one help me with this please!!!


#include <stdio.h>

char _stdcall _export Read_SerialPort(void)

{
char data[100]="Hello";
return *data;
}

void main ()
{
char result[100]="";
*result= Read_SerialPort();
}

Thnaks in advance....
 
You need to change :

char _stdcall _export Read_SerialPort(void)

to :

char* _stdcall _export Read_SerialPort(void)

because you are just declaring to return a single char, instead of a char pointer.

Also, you will need to malloc() the char* you return in that function, else you will get unexpected results. Obviouslt your calling function will need to free() the pointer to avoid memory leaks.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top