CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    May 2009
    Posts
    12

    Question Need help with Void*

    The malfunctioning code snippet:
    Code:
    	ifstream uFile;
    	struct stat results;
    	char filePath[fileName.size()]; 
    	chstr(fileName,*filePath);
    	
    	uFile.open(filePath, ios::in | ios::binary);
    	
        if ( !uFile.is_open() )
        {
        	return false;
        }
        
        stat(filePath, &results);
        
        if (results.st_size <= 0)
        {
        	return false;
        }
        
        archFiles[fileAmt] = malloc(results.st_size+1);
        uFile.read(((char*)archFiles[fileAmt]),results.st_size);
    I don't have a clue whats wrong with it!

    Anyway, more in depth the last two lines are the problem.
    Everytime it gets to uFile.read the program crashes.

    A note:
    archfiles is defined as such:
    Code:
    void * archFiles[];
    I'm certain the problem lies in archFiles[fileAmt] but I haven't a clue whats wrong with it. Even an attempt to print out the value of the pointer (after the malloc ofc) results in a crash at the print statement!

    Edit: More info, I'm using windows and my compiler is g++
    Last edited by wd40bomber7; May 23rd, 2009 at 02:25 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured