Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Urgent help needed please

Options
  • 16-03-2005 4:24pm
    #1
    Registered Users Posts: 221 ✭✭


    Hi i hope some can help me

    i need to out put a varible in a message box so i can see where the value is being corrupted it's a char[15] ,

    i'm using visual c++ 6.0

    thanks


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


       MessageBox(&my_char, "Corrupt?", MB_ICONQUESTION | MB_OK);
    

    Something like that perhaps. I could be wrong as I don't know C++. Although I suspect the char[15] is actually an array so you'll have to loop through each element, heh.


  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    Elfman wrote:
    Hi i hope some can help me

    i need to out put a varible in a message box so i can see where the value is being corrupted it's a char[15] ,

    i'm using visual c++ 6.0

    thanks

    You could use the debugger...
    And set a breakpoint on the variable set to trigger when the memory is written to.


  • Registered Users Posts: 6,508 ✭✭✭daymobrew


    While the debugger is the best option, the code for putting in a message box is:
    char my_char[15];
    
    /* code to initialise and corrupt my_char goes here */
    
    /* Remove the & from earlier suggestion. */
    MessageBox(my_char, "Corrupt?", MB_ICONQUESTION | MB_OK);
    


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Soz, I thought LPCTSTR meant it required a pointer. My bad.


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    Evil Phil wrote:
    Soz, I thought LPCTSTR meant it required a pointer. My bad.

    It does. Where you have char test[20];, test IS a pointer, to that array. :)


  • Advertisement
  • Closed Accounts Posts: 447 ✭✭MickFarr


    Here ya go,
    //////////////////////////////////////////////////////////////////////////////
    // FUNCTION : DisplayChars		                                    //
    // PURPOSE  :                                                               //
    //////////////////////////////////////////////////////////////////////////////
    void CClassName::DisplayChars() 
    {
       char buff[128];
       char MyChar[] = "How much wood could a would chuck chuck if a wood chuck could chuck chukwa";
    
       // Display messagebox for char[15]
       wsprintf(buff, "char 15 = %c", MyChar[15]);
       MessageBox(buff, "Character Number 15", MB_OK);
    
       // Or you can Loop through all the characters
       for(int i=0;  i < strlen(MyChar); i++)
       {
          wsprintf(buff, "char pos %d = %c\\nPress yes to continue", i, MyChar[i]);
          if(MessageBox(buff, "Character Loop", MB_ICONQUESTION | MB_YESNO) == IDNO)
             break;
       }
    	
    }
    


Advertisement