Tracing a simple code !!

I want the program to put a space in this location :
array [1].sentence[index[counter-2]] = ' ' ;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# include <iostream>
# include <algorithm>
# include <string>
using namespace std;
struct name
{
	string sentence ;
} ;
int main ()
{ 
	name array [100] ;
	int counter = 0 , index [10000] ;
	while (counter < 2 && getline (cin , array[counter].sentence ))
	{
		index [counter] = array[counter].sentence.length () ;
		counter ++ ;
	}
	sort (index , index+counter) ;
	
	for (int i=0 ; i<index[counter-1]-index[counter-2] ; i++ )
	{
		array [1].sentence[index[counter-2]] = ' ' ; // this is not working.....I need to put a space int that location
	}
	
	for (int j=0 ; j< index [counter-1]; j++)
	{
		for (int i=0 ; i<=counter-1 ; i++)
		{
			cout << array [counter-1-i].sentence[j];
		}
		cout << endl;
	}

	system ("pause");
}
Works for me:
Blood for the blood god!
Science for the science god!!
SB
cl
io
eo
nd
c
ef
 o
fr
o
rt
 h
te
h
eb
 l
so
co
id
e
ng
co
ed
 !
  <-Here is your space (instead of 'g' in original)
o
d
!
!
Last edited on
It is working.
try this and you'll see.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# include <iostream>
# include <algorithm>
# include <string>
using namespace std;
struct name
{
	string sentence ;
} ;
int main ()
{ 
	name a [100] ;
	int counter = 0 , index [10000] ;
	while (counter < 2 && getline (cin , a[counter].sentence ))
	{
		index [counter] = a[counter].sentence.length () ;
		counter ++ ;
	}
	sort (index , index+counter) ;
	
	for (int i=0 ; i<index[counter-1]-index[counter-2] ; i++ )
	{
		a[1].sentence[index[counter-2]] = ' ' ;
		cout<<a[1].sentence[index[counter-2]]<<"Correct"<<endl; 
	}
	

	system ("pause");
}
can any one try this input for me please :

Rene Decartes once said,
"I think, therefore I am."

I expert it will get u an error (string out of range)
if that happened can anyone propose other soution
Topic archived. No new replies allowed.