May 13, 2012 at 11:09pm UTC
If code1 and code2 has type std::string you call the function as
input(&code1, &code2);
May 13, 2012 at 11:22pm UTC
does not work, identifier code1 and code2 not identified.
May 13, 2012 at 11:28pm UTC
In function
void decoder1(char*decoder1)
{
decoder1[0]='H';
decoder1[1]='o';
decoder1[2]='w';
decoder1[3] ='A';
decoder1[4]='r';
decoder1[5]='e';
decoder1[6]='Y';
decoder1[7]='o';
decoder1[8] ='u';
input(string&code1,string&code2);
//....
you did not define variable code1 and code. Where were they defined?!
May 13, 2012 at 11:32pm UTC
input(string&code1,string&code2); string inside the parameter?
May 13, 2012 at 11:51pm UTC
I wasn't sure if i can call a string pointer using a char pointer so I changed everything to string, since I can modify string with arrays.
My error is
input(&decoder1,&decoder2); arguement string not compatiable with parameter string?
&code1[0] = decoder1[0]; Code1 not identifiable, but i am calling code1 from void input?
&code2= decoder2; expression must be modifiable value?
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
void input(string*code1, string*code2)
{
*code1 = "Lbhr`hfgreX`X`UXergjbrg[\aZfrTUbhgrgb`beebjyfrfhce\fXrTggTV^-" ;
*code2 = "Oz&hkmoty&vxkioykr&gz&tuut2>j&znk&zuv&ykixkz&ruigzout&oy&" ;
}
void decoder1(string*decoder1)
{
decoder1[0]='H' ;
decoder1[1]='o' ;
decoder1[2]='w' ;
decoder1[3] ='A' ;
decoder1[4]='r' ;
decoder1[5]='e' ;
decoder1[6]='Y' ;
decoder1[7]='o' ;
decoder1[8] ='u' ;
string decoder1; string decoder2;
input(&decoder1,&decoder2);
&code1[0] = decoder1[0];
&code1[1] = decoder1[1];
&code1[2] = decoder1[2];
&code1[3] = decoder1[3];
&code1[4] = decoder1[4];
&code1[5] = decoder1[5];
&code1[6] = decoder1[6];
&code1[7] = decoder1[7];
&code1[8] = decoder1[8];
&code1[9] = decoder1[9];
}
void decoder2(string*decoder2)
{
decoder2={'I' ,'A' ,'m' ,'F' ,'i' ,'n' ,'e' };
string code1; string code2;
input(&code1,&code2);
&code2= decoder2;
}
void output()
{
string output1; string output2;
decoder1(&output1);
decoder2(&output2);
cout << output1 << endl;
cout << output2 << endl;
}
int main()
{
output();
return 0;
}
Last edited on May 13, 2012 at 11:52pm UTC
May 13, 2012 at 11:58pm UTC
This code
void decoder1(string*decoder1)
{
decoder1[0]='H';
decoder1[1]='o';
decoder1[2]='w';
decoder1[3] ='A';
decoder1[4]='r';
decoder1[5]='e';
decoder1[6]='Y';
decoder1[7]='o';
decoder1[8] ='u';
string decoder1; string decoder2;
input(&decoder1,&decoder2);
&code1[0] = decoder1[0];
&code1[1] = decoder1[1];
&code1[2] = decoder1[2];
&code1[3] = decoder1[3];
&code1[4] = decoder1[4];
&code1[5] = decoder1[5];
&code1[6] = decoder1[6];
&code1[7] = decoder1[7];
&code1[8] = decoder1[8];
&code1[9] = decoder1[9];
}
is invalid. Before to do something you shall understand what you are doing.
May 14, 2012 at 8:56am UTC
No, it is still a worse code. You may not use for example the subscript operator for a string object if you did not allocate enough memory. So you may not write
string decoder;
decoder[0]='H';
decoder[1]='o';
decoder[2]='w';
decoder[3] ='A';
decoder[4]='r';
decoder[5]='e';
decoder[6]='Y';
decoder[7]='o';
decoder[8] ='u';
Either use
string decoder;
decoder[0] += 'H';
decoder[1] += 'o';
decoder[2] += 'w';
decoder[3] += 'A';
decoder[4] += 'r';
decoder[5] += 'e';
decoder[6] += 'Y';
decoder[7] += 'o';
decoder[8] += 'u';
or use append member function
string decoder;
decoder.append( 'H' );
decoder.append( 'o' );
decoder.append( 'w' );
decoder.append( 'A' );
decoder.append( 'r' );
decoder.append( 'e' );
decoder.append( 'Y' );
decoder.append( 'o' );
decoder.append( 'u' );
Also it is a bad idea to assign the same name to a function and its parameter as in tou code
void decoder2 (string*decoder2 )
The bold statement is invalid. You are trying to assigne an object of type std::string to a poinetr.
void decoder2(string*decoder2)
{
decoder2={'I','A','m','F','i','n','e'};
string code1; string code2;
input(&code1,&code2);
&code2= decoder2;
}
Last edited on May 14, 2012 at 9:12am UTC
May 14, 2012 at 10:23am UTC
This makes no sense whatsoever:
&code2= decoder2;
You're trying to adjust the address of code2. As in, move it in memory. That's not something you can do.