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

前端 未结 6 497
星月不相逢
星月不相逢 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:38

    If you are looking to return a string from a function (other than main), you should do something like this.

    #include 
    
    const char * getString();
    
    int main()
    {
        printf("Hello, World!\n");
        printf("%s\n", getString());
        return 0;
    }
    
    const char * getString()
    {
        const char *x = "abcstring";
        return x;
    }
    

提交回复
热议问题