+ 2

help me in my string reverse function

I don't know why the compiler is showing No Output in my function. if you change my code please make comments so i can know where was the mistake. I will delete this question after the answer because I dont want sololearn Q/A section to be full with these kind of code problems. https://code.sololearn.com/cy61oC6W8wGz/?ref=app

7th Aug 2019, 2:43 PM
Robin Singh
Robin Singh - avatar
2 Respostas
+ 4
Nice code man! There are three reasons why you don't get any output. 1- You should declare reverse as "char *" and not only "char". You are in fact returning a pointer to char (that is, a string) 2- In the first "for cycle" you compare a char with "\0", but if you write "\0", this is a string. I you want to treat \0 as a char you should write '\0' instead. 3- When you write "Hello", this is a "const char*" and you can't modify it. In order to use your function you have to declare a separate variable and pass it to your function: ... char s[] = "Hello"; printf("%s", reverse(s)); ... Hope this helped!
7th Aug 2019, 3:01 PM
Paolo Luigi Rinaldi
Paolo Luigi Rinaldi - avatar
+ 1
https://code.sololearn.com/cXX2RXxrmuPK/?ref=app Thanks bro you helped me a😃lot.
7th Aug 2019, 8:24 PM
Robin Singh
Robin Singh - avatar