How to return pointer to a string from a function in C

1 Answer

0 votes
#include <stdio.h>
   
char *rp(char *str);   
   
int main(int argc, char **argv) 
{ 
    char s[16] = "abc";
   
    puts(rp(s));
    
    return 0;
}

char *rp(char *str)
{
    char *p, *tmp;
    
    p = tmp = str;
    while(*p)
    {
         *p = *p + 1;
         p++;
    }

    return(tmp);
}
   
/*
  
run:
   
bcd

*/

 



answered Sep 28, 2015 by avibootz
...