I have a problem here :(
I create here multiple global variables and put them into an array. In funktion extractLabel()
I fill these variables with binary code values per variable = binarycode
. I print them out and everything is alright. Then I print the same variables out from the array. But there the variables have the values 0. But shouldn't these variables have the same value in the array, too? If not, how I could fix this?
Thank you for helping!
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <array>
#include <math.h>
#include <algorithm>
#include "Client.hpp"
static long long a_word = 4294967295;
static long long c_word;
static long long c_label1;
static long long c_label2;
static long long c_label3;
static long long c_label4;
static long long c_label5;
static long long c_label6;
static long long c_label7;
static long long c_label8;
static std::vector<bool> binCode;
static std::array<long long, 8> c_tokens = {c_label1, c_label2, c_label3, c_label4, c_label5, c_label6, c_label7, c_label8};
void executeClient() {
receiveValue();
calculateDecBin();
extractLabel();
}
void receiveValue() {
c_word = a_word;
}
void calculateDecBin() {
while (c_word) {
int rest = c_word % 2;
c_word = c_word / 2;
binCode.push_back(rest);
}
std::reverse(binCode.begin(), binCode.end());
}
void extractLabel() {
std::cout << "Label values:" << std::endl;
for(int i = 0; i < 8; i++) {
c_label1 = stoll(std::to_string(c_label1) + std::to_string(binCode[i]));
}
std::cout << c_label1 << std::endl;
for(int i = 8; i < 10; i++) {
c_label2 = stoll(std::to_string(c_label2) + std::to_string(binCode[i]));
}
std::cout << c_label2 << std::endl;
for(int i = 10; i < 26; i++) {
c_label3 = stoll(std::to_string(c_label3) + std::to_string(binCode[i]));
}
std::cout << c_label3 << std::endl;
for(int i = 26; i < 27; i++) {
c_label4 = stoll(std::to_string(c_label4) + std::to_string(binCode[i]));
}
std::cout << c_label4 << std::endl;
for(int i = 27; i < 28; i++) {
c_label5 = stoll(std::to_string(c_label5) + std::to_string(binCode[i]));
}
std::cout << c_label5 << std::endl;
for(int i = 28; i < 29; i++) {
c_label6 = stoll(std::to_string(c_label6) + std::to_string(binCode[i]));
}
std::cout << c_label6 << std::endl;
for(int i = 29; i < 31; i++) {
c_label7 = stoll(std::to_string(c_label7) + std::to_string(binCode[i]));
}
std::cout << c_label7 << std::endl;
for(int i = 31; i < 32; i++) {
c_label8 = stoll(std::to_string(c_label8) + std::to_string(binCode[i]));
}
std::cout << c_label8 << std::endl;
std::cout << "array values:" << std::endl;
for(int i = 0; i < c_tokens.size(); i++) {
std::cout << c_tokens[i] << std::endl;
}
}