Return a char array with any length in C?

How do I return a char array with any length in C?

char string[](int, int);

doesn't work; is there a way to return a char array?

1 answer

  • answered 2021-10-24 18:30 Bill Lynch

    You are unable to do that in C. Instead, return a pointer.

    char *string(int length, int unused) {
      char *s = calloc(x, sizeof(char));
      return s;
    }
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum