Example
void
main(
int
argc,
char
* argv[]) {
for
(
int
i =
0
; i < argc; i++ ) {
cout << argv[ i ] );
i = i +
1
;
}
}
Solution
Move the assignment-to-control variable from inside of the for loop to the increment clause of the loop.
void
main(
int
argc,
char
* argv[]) {
for
(
int
i =
0
; i < argc; i = i +
2
) {
cout << argv[ i ] ;
}
}
Solution
Change the
for
loop to a
while
loop
void
main(
int
argc,
char
* argv[]) {
int
i =
0
;
while
( i < argc ) {
cout << argv[ i ] ;
i = i +
2
;
}
}