Re: First program in C - what is going on with function returns?
- From: "Bill Pursell" <bill.pursell@xxxxxxxxx>
- Date: 30 Apr 2006 05:50:11 -0700
ben.carbery@xxxxxxxxx wrote:
Thanks for the detailed response!
speakdate(int d, int m, int y)
What type is being returned? If you meant "nothing", specify void.
As per last reply, I want to return a string, but am not sure of the
syntax for returning arrays...
You can't return an array, but you can return a pointer to the first
entry.
#include <stdio.h>
#include <string.h>
#define MAX_LENGTH 256
char * foo(void)
{
static char ret[MAX_LENGTH];
strncpy(ret, "test", MAX_LENGTH);
return ret;
}
int main(void)
{
printf("%s\n", foo());
return 0;
}
.
- References:
- First program in C - what is going on with function returns?
- From: ben . carbery
- Re: First program in C - what is going on with function returns?
- From: Kelsey Bjarnason
- Re: First program in C - what is going on with function returns?
- From: ben . carbery
- First program in C - what is going on with function returns?
- Prev by Date: Re: Boost process and C
- Next by Date: Re: Question about (double *)NULL
- Previous by thread: Re: First program in C - what is going on with function returns?
- Next by thread: Re: First program in C - what is going on with function returns?
- Index(es):
Relevant Pages
|