CPP / C++ / C Code:
char cTotalCharNames[111], cCharacterName[11], cTotalChar;
for (i = 0; i <= cTotalChar; i++) {
memset(cCharacterName, 0, sizeof(cCharacterName));
memcpy(cCharacterName, cTotalCharNames[i*11], 10);
wsprintf(G_cTxt, "Character (%s) added", cNewCharName);
}
well the array cTotalCharNames is [111] in size and i want to write all the possible character names into it using memcpy moving 11 places after each name for example the first name would go into spots spaces 1 to 11, then the 2nd name would go into 11 to 22 etc.. Except when i am running this code it makes an access violation. If i change "memcpy(cCharacterName, &cTotalCharNames[i*11], 10);" It stops the access violation but the name isnt copied. what am i doing wrong...
edit:
i need to add a few things which i forgot to add. If no "&" or "(char *)" is added before cTotalCharNames[i*11], i get the error:
error C2664: 'memcpy' : cannot convert parameter 2 from 'char' to 'const void *'
cTotalChar is initially 0, and reads a file and returns a number does not exceed 8 - 4 characters for abaddon 4 characters for apocalypse. The access violation occurs on the first attempt to go through "for (i = 0; i <= cTotalChar; i++) {." Breakpoints tell me that as soon as the line " memcpy(cCharacterName, cTotalCharNames[i*11], 10);" is processed it crashes.
There is code to write from cTotalCharNames[i*11] and to write to cTotalCharNames[i*11]. The above code in this case is from, below is the example of to:
CPP / C++ / C Code:
Code: Select all
memcpy(cTotalCharNames[cTotalChar*11], cNewCharacterName, 10);