c++ looping string array

We would like to question about the condition of for loop that can make us store the 4th element in the string array'n' into another array called x
so we want x to contain all the 4th elements of n string array and we stopped at the condition of for loop
can anybody help ?
this code isn't working .
1
2
3
4
5
6
7
8
 
string x[100];

int w=3;
for ( int i=0;i<100 ;i=i++)
	{ x[i]=n[w];
	w=w+4;
}
You just need to increment the value of counter-variable "i" by 4.
The following changes will accomplish your requirement.

string x[100];
for ( int i=0;i<100 ;i=i+4)
{
x[i]=n[i];
}

By doing this the counter-variable will directly jump to the next index number which is the multiple of 4.
Hope this helps!
Last edited on
Topic archived. No new replies allowed.