+ 2

Reverse string

hello guys, I tried to make a program that reverse a string using pointer but, it does not work when I input a string having spaces.so please help me to ignore those spaces in my code. I want to reverse a string through pointer not by array. below is my code link:- https://code.sololearn.com/cO91O6NopjBi/?ref=app

10th Mar 2018, 4:12 PM
Vivek Mishra
Vivek Mishra - avatar
7 Respostas
+ 8
you can use getline() function instead of cin to read string with spaces
10th Mar 2018, 4:13 PM
Vukan
Vukan - avatar
+ 3
Just use std::reverse of <algorithm>.
10th Mar 2018, 4:43 PM
Timon Paßlick
0
problem solved
11th Mar 2018, 6:21 AM
Vivek Mishra
Vivek Mishra - avatar
0
//based on Donnas answer import java.util.Scanner; class Rev { public static void main(String[] args) { System.out.print(new StringBuffer(new Scanner(System.in).nextLine()).reverse()); } }
21st Mar 2018, 2:10 PM
Timon Paßlick
0
https://code.sololearn.com/cNeIN0BB018d/?ref=app I Hope this thing will help you
22nd Mar 2018, 6:47 PM
Amir Shah
Amir Shah - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String a = scanner.nextLine(); String b = new StringBuilder(a).reverse().toString(); System.out.println(b); } }
24th May 2021, 12:59 PM
saravanan manickam
- 1
getting an error message after using getline() .will u please modify my code
10th Mar 2018, 4:25 PM
Vivek Mishra
Vivek Mishra - avatar