Help with calling functions
I want the main to read both decoder1 and decoder2 functions. Currently it only reads decoder1. I am not sure how to read them both.
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
|
#include <iostream>
#include <string>
using namespace std;
void input(char arrays[])
{
int ARRAY_SIZE=256;
cout << "input code 1" << endl;
cin.getline( arrays, ARRAY_SIZE );
cout << "input code 2" << endl;
cin.getline( arrays, ARRAY_SIZE );
}
void decoder1(char paraDecoder1[])
{
paraDecoder1[0]='H';
paraDecoder1[1]='o';
paraDecoder1[2]='w';
paraDecoder1[3]='A';
paraDecoder1[4]='r';
paraDecoder1[5]='e';
paraDecoder1[6]='Y';
paraDecoder1[7]='o';
paraDecoder1[8]='u';
paraDecoder1[9]=0;
}
void decoder2(char paraDecoder2[])
{
char str[]= { 'I', 'A', 'm', 'F', 'i','n','e', '\0' };
paraDecoder2=str;
}
void output(char elements[])
{
cout << elements << endl;
}
int main()
{
char line1[256]; char line2[256];
input(line1);
decoder1(line1);
decoder2(line2);
output(line1);
output(line2);
system("pause");
}
|
1 2 3 4
|
cout << "input code 1" << endl;
cin.getline( arrays, ARRAY_SIZE );
cout << "input code 2" << endl;
cin.getline( arrays, ARRAY_SIZE );
|
Suppose that you are executing the instructions.
¿what will the value of 'arrays' at the end?
¿What's the purpose of
decoder1()? As it is, you are overwriting the inputted value.
1 2 3 4 5 6
|
//void decoder2(char paraDecoder2[])
void decoder2(char *paraDecoder2) //equivalent
{
char str[]= { 'I', 'A', 'm', 'F', 'i','n','e', '\0' };
paraDecoder2=str; //changing a local variable
}
|
¿Does it makes sense to you? ¿what is that supposed to do?
Topic archived. No new replies allowed.