+ 2

Reverse and gets

I was trying to learn some string functions but i noticed that strrev() and gets() does not work in the SoloLearn playground. Does anyone know why?

8th Jan 2020, 2:32 PM
Keith Alcantara
Keith Alcantara - avatar
3 Answers
+ 3
as you have started learning c++ you can use reverse function to reverse string in c++ #include <iostream> #include <algorithm> using namespace std; int main() { string s="reverseit"; reverse(s.begin(),s.end()); cout<<s; return 0; }
8th Jan 2020, 3:27 PM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar
+ 2
Both functions are removed from C. You can still use fgets() as an alternative to gets(), but you have to implement yourself a function to reverse a string.
8th Jan 2020, 2:57 PM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
+ 1
strrev isn't included in the <strings.h> header for linux, best try to implement one such as the attached code. As for gets, its not recommended due to memory possible overwritten out of bounds. https://code.sololearn.com/cO26g6EB47ma/?ref=app
26th Jan 2020, 11:27 AM
0x6176696c61
0x6176696c61 - avatar