-
strings
First Question.
how would i load a file with numbers such as
20
35
10
50
and break them down into 2 arrays
i.e.
array[4] = { 2, 3, 1, 5}
array2[4] = { 0, 5, 0 , 0}
Second Question.
how would i change an int array into a char array?
thanks for any help
-
>>>>how would i load a file with numbers such as
20
35
10
50
and break them down into 2 arrays
i.e.
array[4] = { 2, 3, 1, 5}
array2[4] = { 0, 5, 0 , 0}
This looks cool but have you thought like this maybe.
array[2] = {20, 35} //your setting up an array of 2 elements with numbers 20 and 35 being initialized into those elements.
array2[2] = {10, 50} //same thing
>>>>>>how would i change an int array into a char array?
char array[4] = {'2', '3', '1', '5'} //must use ' ' for char and " " for strings.
Is that what your asking for?
cj
;)
-
for the first question though i want to break it down into 1 number each so that i can apply some simple encryption to them
-
Read the first char, put it in the first array (element 1).
Read the next char, put it in the second array (element 1).
Read the next char, which is the line break, discard it.
Read the next char, put it in the first array (element 2).
Read the next char, put it in the second array (element 2).
Read the next char, which is the line break, discard it.
...etc...
-
Why not...
Code:
ifstream infile("/home/user/file.txt", ios::in);
char array1[4];
char array2[4];
for (int i = 0; i < 4; ++i) {
infile >> array1[i] >> array2[i];
}
This is the C++ board, right?
So use C++ extraction operator to pull a char at a time, which already ignores line breaks and such.
-
i think i got it now, thanks for the help