Thread: Why am I having an access violation?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    cout << "Bye World!";
    Join Date
    Jun 2006
    Posts
    40

    Why am I having an access violation?

    Here is my code:
    Code:
    	double **double_array;
    	double_array = new double*[rows];
    	for(int i=0;i<rows;i++)
    		double_array[i] = new double[columns];
    	char split[3];
    	strcpy(split, ",;");
    	for(int i=0;i<rows;i++)
    		for(int j=0;j<columns;j++)
    			double_array[i][j] = charToDouble(strtok((i==0&&j==0)?&input[1]:NULL,split));
    The rows and columns have already be determined to be positive nonzero integers (actually, they are 2 and 2). The char* input contains "[3,2;1,2]" (I called strcpy(input, "[3,2;1,2]")). When I run it through the MSVC++ 2005 debugger, it tells me that I have an access violation and the line that it points to is line 120 of strtok.c (included by the <string> header I assume), so I figure that there is something wrong with my call to strtok. This happens when i=j=0, but it might also happen afterwards (it never gets that far). charToDouble takes in a char* and returns a double. I should probably rename it to charArrayToDouble or stringToDouble.

    Hopefully, I will figure it out the second I push the "Submit New Thread" button, as has happened before, but I doubt it. So here goes. Any ideas? Thanks in advance.
    Last edited by ldb88; 06-10-2007 at 06:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Access violation... can't figure it out...
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2007, 10:52 AM
  2. access violation in int array
    By George2 in forum C Programming
    Replies: 2
    Last Post: 08-02-2007, 11:28 PM
  3. FtpFileFind access violation with MS VC++ 6.0
    By earth_angel in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 07:02 PM
  4. Help! CListCtrl access violation
    By bonkey in forum Windows Programming
    Replies: 4
    Last Post: 11-18-2003, 02:40 PM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 02:46 PM