[Access Violation]: Debug Help
Just trying to put null characters into an array. Might sound easy.. but even this little snippet of code makes my pc go crazy.
This will compile, but will hang up at runtime.. and will cause an, "access violation" when ran through the debugger:
Code:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int iCount = 3;
char **Lines = new char*[3];
Lines[0] = "H1007, 1-24\0",
Lines[1] = "A, 25-36\0",
Lines[2] = "H1007, 37-48\0";
//Visual Verification: everything works fine
for(int i=0; i<3; i++)
cout << Lines[i] << endl;
char **Name = new char*[iCount];
char **FiberCount1 = new char*[iCount];
char **FiberCount2 = new char*[iCount];;
int /*size,*/ word_index;
bool cont = true;
i=0;
for(int j=0; i<iCount; i++, j=0)
{
word_index = 0;
cont = true;
do{
//Extract Fiber Name
while(Lines[i][j]!=',')
{
j++;
}
//At this point, i==0 and j==5
Lines[i][j]='\0'; //This line causes "access violation"
Name[i] = new char[j-word_index+1];
strcpy(Name[i], Lines[i]+word_index);
//Name[i][j-word_index] = '\0';
...
...
...
any ideas/suggestions on what to do would be cool
using MVSC++ 6.0 (mostly for testing/debugging)