problems with char * return from a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All

I am calling a function x within strcpy as follows

strcpy(a,x("sample text","default text"));

x is defined as follows

char * x(char *m, char *n)
{
	char *return_val=NULL;
	if (check m is in database)
		return_val=m;
	else
		return_val=n;
	return(return_val);
}
 This causes  the array a to have a corrupted string. The string is either m or n but with illegal characters appended.
So I tried the following
char *temp=NULL
temp=x("sample text","default text");
strcpy(a,temp);


When I printed temp, it looked file, but when I printed a it was garbled. I had initialized as a[0]='\0';

The same program works fine in Sun and IBM. Is there anything in GCC that I need to use as flag to have this not occur?
Any help or pointers will be greatly appreciated.

Thanks in advance

With Regards

Vardhan




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux