Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Urgent help needed please

  • 16-03-2005 04:24PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 6,651 ✭✭✭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, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


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


  • Registered Users, Registered Users 2 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