hi,
ive written string reverse program, which looks like this - just an example for my problem:
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
|
#include <iostream>
using namespace std;
int main()
{
char s[256];
cout << "Enter a string: ";
cin >> s;
cout << "Reversed string = ";
int length = strlen(s);
int cnt1 = 0;
for ( int cnt2 = (length - 1); cnt2 > (length - 1)/2 ; cnt2--)
{
int temp = s[cnt1];
s[cnt1] = s[cnt2];
s[cnt2] = temp;
cnt1++;
}
for(int i = 0; i < length; ++i)
cout << s[i];
cout << endl;
}
|
but if i replace int cnt1 = 0; and cnt1++; with:
|
for ( int cnt1 = 0, int cnt2 = (length - 1); cnt2 > (length - 1)/2 ; cnt1++, cnt2--)
|
i get these errors:
- error C2062: type 'int' unexpected
- error C2065: 'cnt2' : undeclared identifier
- error C2065: 'cnt2' : undeclared identifier
- error C2143: syntax error : missing ';' before ')'
- error C2143: syntax error : missing ';' before ')'
- error C2143: syntax error : missing ';' before '{'
- error C2065: 'cnt2' : undeclared identifier
- error C2065: 'cnt2' : undeclared identifier
but this is just an example, it does similer with any other for loop, if there is more then one argument specified in the 1. and 3. argument "space" of a for loop
ty in advance!