Horje
how to return array of char in c Code Example
how to return array of char in c
char *foo(int count) {
    char *ret = malloc(count);
    if(!ret)
        return NULL;

    for(int i = 0; i < count; ++i) 
        ret[i] = i;

    return ret;
}
return char array in c
char * createStr() {

    char char1= 'm';
    char char2= 'y';

    char *str = malloc(3);
    str[0] = char1;
    str[1] = char2;
    str[2] = '\0';

    return str;

}
how to return array of char in c
int main() {
    char *p = foo(10);
    if(p) {
        // do stuff with p
        free(p);
    }

    return 0;
}
How to return a char array from a function in C
#include <stdio.h>
#include <string.h>
    char* createStr(){
    static char str[20] = "my";
    return str;
}
int main(){
    char a[20];
    strcpy(a,createStr()); //this will copy the returned value of createStr() into a[]
    printf("%s",a);
    return 0;
}




C

Related
vim vertical line at 80 characters Code Example vim vertical line at 80 characters Code Example
strcpy c Code Example strcpy c Code Example
enregistrement en c Code Example enregistrement en c Code Example
c memcpy Code Example c memcpy Code Example
how to take blank space in c scanf Code Example how to take blank space in c scanf Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12