Return a string from function to main

后端 未结 3 1840
南笙
南笙 2020-12-18 17:28

I want to return a string from a function (in the example funzione) to main. How to do this? Thank you!

#include 
#include 

        
3条回答
  •  一生所求
    2020-12-18 17:44

    #include 
    #include 
    
    #define SIZE 10
    
    const char *funzione (void){
        const char *string = "Example";
    
        if(strlen(string) >= SIZE)
            return "";
    
        return string;
    }
    
    int main(void){
        char stringMAIN[SIZE];
    
        strcpy(stringMAIN, funzione());
    
        printf("%s", stringMAIN);
    
        return 0;
    }
    

提交回复
热议问题