Re: First program in C - what is going on with function returns?




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;
}

.



Relevant Pages

  • (patch for Bash) regex conditional tests
    ... 'regex' are returned in array variable SUBMATCH. ... Skipping of positional parameters, array elements, string ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: passing char arrays by reference
    ... I want to pass an array of strings to a function: ... int stuff{ ... stuff is an incompatible pointer type. ... string type; a "string" is a data format, ...
    (comp.lang.c)
  • Re: String of numbers into to array of numbers
    ... then read that string and have the string show the ... individual numbers as in an array. ... int arryCnt = 0; ... qStr= cStr.substring); ...
    (comp.lang.java.help)
  • Re: Reduce blanks
    ... >>> The syntax is valid PLI. ... > DF's function converts an array to a string, or a string to an array. ... I see you have removed the Fortran cross-post probably because of your many ...
    (comp.lang.pl1)
  • Re: How to Return an array of strings in C (char**)
    ... int start=0; ... // to know the number of elements in the array ... The reason is that you fail to increment str. ... The you could have printed "here" before entering the main loop to see if you actually got there, then str + start to see where you go to in the string on each pass. ...
    (comp.lang.c)