How can I return a string to the operating system in my C code?

前端 未结 6 484
星月不相逢
星月不相逢 2020-12-16 04:14

I am a C beginner and this is my C code:

#include 
#include 

main()
{
    printf(\"Hello, World!\\n\");
    return \'sss\';
}         


        
6条回答
  •  失恋的感觉
    2020-12-16 04:19

    You could do this in a way similar to scanf. In other words:

    void foo(char **value_to_return) {
        *value_to_return = malloc(256); // Store 256 characters
        strcpy(*value_to_return, "deposited string");
    }
    
    int main() {
        char *deposit;
        foo(&deposit);
        printf("%s", deposit);
        return 0;
    }
    

提交回复
热议问题