-4
vector<vector<int>> mapVector(maxX, vector<int>(maxY));
char* mapBuffer = new char[mapString.size() + 1];
...
mapVector[i][j] = mapBuffer[y];
...

mapBuffer[i][j] contains the '#" symbol but after the "mapVector[i][j] = mapBuffer[y]" mapVector[i][j] contans number "35". Why is it passing on the id instead of the symbol?

Henrik
  • 23,186
  • 6
  • 42
  • 92
Nikita Rostov
  • 29
  • 1
  • 4

1 Answers1

-1

Here is how to see the data using printf:

#include <stdio.h>
int main (int argc, char **argv){
    char test='#';
    printf("test %c %d\n", test,test);
    return 0;

}

%c renders as a char %d renders as an int

(The above is in C but that part of C that will be compiled by a C++ compiler)

So in your code if you change your vector to a vector of char you will not have the issue:

 vector<vector<char>> mapVector(maxX, vector<char>(maxY));
 char* mapBuffer = new char[mapString.size() + 1];
 ...
 mapVector[i][j] = mapBuffer[y];
 ...
Matthew V Carey
  • 196
  • 1
  • 10
  • I am not 100% sure that it works on big endian architecture without a cast. But I compiled and ran it before I posted it on a little endian x86 box. – Matthew V Carey Dec 09 '14 at 11:32
  • Just built and ran it on a PPC Mac running OSX still works, that is big endian. – Matthew V Carey Dec 09 '14 at 11:52
  • 1
    why not use C++, which OP is using? – zoska Dec 09 '14 at 11:56
  • C++ is a super set of C and I was trying to show something very simple. The OP did not show what the type mapVector was just that it has two subscripts, I don't want to explicitly fix their code in a cut and paste way, I just want to show them what they are seeing and give them a clue as to how to fix it. – Matthew V Carey Dec 09 '14 at 12:01
  • first: mapVector is vector (which is C++ stl), second: C++ is not a super set of C, it's a different language (which happens to be compatible with C), third: question is tagged C++ – zoska Dec 09 '14 at 12:04
  • Well then the clue is in the which is being assigned the value of a char, but when it is looked at later it is an int hence the number. – Matthew V Carey Dec 09 '14 at 12:06