C
c_monty
I am used to Delphi and VB, where functions can return strings. I
recently starting learning C and my findings are that you can have
external functions build strings, but the function cannot return the
string itself, rather, it needs to update a variable that is an array or
points to an array. Correct?
Below is a 'simple' test to work with a string that was created in an
external function (and external file). Based on the result I get (_@),
I know I don't fully "get it" yet. Any help would be appreciated.
//MAIN.C
#include<stdio.h>
main()
{
char *data_from_function;
my_function(data_from_function);
printf("Data results from My Function: %s\n");
}
//MYFUNCTION.C
my_function(char *strData)
{
strData = "HELLO WORLD\n";
}
(Linux 9 i386)
#gcc main.c myfunction.c
#./a.out
Data results from My Function: _@
recently starting learning C and my findings are that you can have
external functions build strings, but the function cannot return the
string itself, rather, it needs to update a variable that is an array or
points to an array. Correct?
Below is a 'simple' test to work with a string that was created in an
external function (and external file). Based on the result I get (_@),
I know I don't fully "get it" yet. Any help would be appreciated.
//MAIN.C
#include<stdio.h>
main()
{
char *data_from_function;
my_function(data_from_function);
printf("Data results from My Function: %s\n");
}
//MYFUNCTION.C
my_function(char *strData)
{
strData = "HELLO WORLD\n";
}
(Linux 9 i386)
#gcc main.c myfunction.c
#./a.out
Data results from My Function: _@