how to return a char array from a function in C

后端 未结 3 1412
时光说笑
时光说笑 2021-02-04 05:12

I want to return a character array from a function. Then I want to print it in main. how can I get the character array back in main function?



        
3条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 05:46

    #include
    #include
    #include
    char *substring(int i,int j,char *ch)
    {
        int n,k=0;
        char *ch1;
        ch1=(char*)malloc((j-i+1)*1);
        n=j-i+1;
    
        while(k

    This will compile fine without any warning

    1. #include stdlib.h
    2. pass test=substring(i,j,s);
    3. remove m as it is unused
    4. either declare char substring(int i,int j,char *ch) or define it before main

提交回复
热议问题