Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2003
    Location
    Dallas,TX
    Posts
    684

    Question visual studios error please help? c++ unhandled expception

    i got this error today working,i attached a image to explain better,Unhandled expception at 0x004010e0 in main.exe: 0xC0000005: Access violation reading location 0x645c3a63,i get this running this line of code here,
    here is a image of the code and the error,can any help me,i was passing arguments and compling them,Thanks,Chris^_^
    http://img132.exs.cx/img132/183/code0zm.jpg
    http://img132.exs.cx/img132/2138/vs5bc.jpg

  2. #2
    Join Date
    Aug 2004
    Location
    little rock arkansas
    Posts
    3,482

    Re: visual studios error please help? c++ unhandled expception

    you can copy and paste code here

    use the [_PHP] [_/PHP] commands without the under score

    try this code it will print out argument zero and argument 2
    argument zero is the name of the executable

    your error happens because you try to access an array but the varible is just a double pointer(which if **argv[] is used you will only get the memory address of the arguments passed)

    PHP Code:
     #include <iostream>
    using namespace std;
    int main(int argcchar *argv[])
    {

    cout << argv[0];
    cout << "\n" << argv[2];

    return 
    0;


  3. #3
    Join Date
    Dec 2002
    Location
    Toronto
    Posts
    51
    I strongly suspect you have not supplied 2 command line arguments. Try something like this:
    PHP Code:

    cout 
    << "arg count: " << argc;
    if ( 
    argc )
        
    cout << argv[2]; 

  4. #4
    Join Date
    Aug 2004
    Location
    little rock arkansas
    Posts
    3,482
    look closer darth Paul argv is an double pointer
    he is then he is trying to access an array element sub zero
    he then gets an memory access error for accessing memory thats not there

  5. #5
    Join Date
    Mar 2004
    Posts
    0
    hello. i was looking at your code and wondering if you were acualy passing in any arguments? becuse if you were not passing in any args, it would just like doing this:

    PHP Code:

    int 
    array[1];
    array[
    0] = " <insert filename here> ";
    cout<<array[2]; 
    which wouldent work, it woulod be reading wrong memery, and could by chance create an accses violationm, like what happend to you. try and make some code that maks shure there are arguments before trying and reading memery. like this:

    PHP Code:
    #include <iostream>
    #include <stdlib.h>

    using namespace std;

    int main(int argcchar *argv[])
    {
      if( 
    argc )
      {
        
    cout<<"there are no args!";
        return 
    1;
      }
      
    cout<<argv[0]<<"\n";
      
    cout<<argv[2]<<"\n";
      
    system("PAUSE");    
      return 
    0;

    there yah go, that would make shure there are agrs before trying to read them! hope this helps,
    ~metalhead

  6. #6
    Join Date
    Mar 2004
    Posts
    0
    Originally posted by ostamo2
    look closer darth Paul argv is an double pointer
    he is then he is trying to access an array element sub zero
    he then gets an memory access error for accessing memory thats not there
    sorry, dident see your post

  7. #7
    Join Date
    Dec 2002
    Location
    Toronto
    Posts
    51
    Originally posted by ostamo2
    look closer darth Paul argv is an double pointer
    he is then he is trying to access an array element sub zero
    he then gets an memory access error for accessing memory thats not there
    Yes, this is the C/C++ standard method of passing command line arguments to a program. If there are 2 or more arguments, then argv[2] will point to a properly allocated, null-terminated array of characters, otherwise, it will point to the dreaded undefined location, which is why I suggested the OP had passed <2 arguments

  8. #8
    Join Date
    Aug 2004
    Location
    little rock arkansas
    Posts
    3,482
    now i understan darth

    he passed no command line arguments


    that would mess u up also

Posting Permissions

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