Like Tree3Likes
  • 1 Post By nvoigt
  • 1 Post By manasij7479
  • 1 Post By nvoigt

Runs on wxdevc++, but not on OS!

This is a discussion on Runs on wxdevc++, but not on OS! within the C++ Programming forums, part of the General Programming Boards category; Hello all! I need help with a peculiar matter: The code I've written works perfectly when I run it from ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    22

    Runs on wxdevc++, but not on OS!

    Hello all! I need help with a peculiar matter: The code I've written works perfectly when I run it from the compiler, but not well when I run the .exe on the output folder.

    I use wxdev-c++, and this is a wxwidgets program. I've already posted the same problem to the wxdevc++ forum, but I want to have another opinion too. Generally, what sort of problem leads to an executable running fine through the compiler, but not outside it?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Generally speaking, it's probably that your sacgrum is smurfled. That can lead to "issues".



    Could you be a bit more specific than "not well". The last time I was "not well" it was the flu. Consider the link in my sig to ask a good question.
    rags_to_riches likes this.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Quote Originally Posted by Lord Asriel View Post
    Generally, what sort of problem leads to an executable running fine through the compiler, but not outside it?
    I'd guess.. environment variables that the library may use.
    dennis.cpp likes this.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    22
    nvoigt: I understand that giving full details is the usual course of asking for help, but I thought I'd start from the few facts since the program does work in some environment.

    Since more are asked for, however, let me state them. I am trying to make an academic project about graph edhes represented as sparse array elements, linked-by-list, create a spanning tree on it, and find cycles. There are 2 routines of type const char *, that set the value of a rich text control each. So...when run through the compiler, they print the right things. When run through windows explorer, they print either the few first characters (about 40) of the sequence, or nothing.

    Should I post code?

    manasij7479: What library are you referring to? (actually, i'm kind of a newbie; I don't know much about libraries)

  5. #5
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Quote Originally Posted by Lord Asriel View Post
    manasij7479: What library are you referring to? (actually, i'm kind of a newbie; I don't know much about libraries)
    Aren't you using wxwidgets for the gui? ...I was referring to that.
    Compile the program from the terminal, and try to run it from there.... The errors shown there...if any... will directly point out the source of the error .
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    22
    Uh, the "terminal"? If you mean the compiler, I use wxdev-c++, and there are no errors at all.

  7. #7
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,523
    Quote Originally Posted by Lord Asriel View Post
    Uh, the "terminal"? If you mean the compiler, I use wxdev-c++, and there are no errors at all.
    Oh..
    You seem to be confused about the diff between a compiler and an IDE.

    By terminal, I mean the command prompt.
    Simply navigate to the folder of the executable and type its name.....and observe the errors.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    22
    The problem analytically: There is a single (wx)Button. When it is pressed, some of my routines may be run, some others not, but in the end the values of the two rich text controls are set to one of my functions each.
    The program is about saving edges of a graph in a 2-D sparse array (linked list), creating a spanning tree on it, and finding cycles. Being 2D and double-link-listed, the members of the sparse array contain pointers to the previous, next, up and down elements. Also, the edges they represent could or could not be part of the spanning tree (STE=spanning tree edge). This is what const char* print_all_edges() is about, and sets WxRichTextCtrl_sparse->SetValue(print_all_edges()). Then, the program searches for cycles and reports them. This is what const char* const char* print_all_cycles(void) is about, and sets
    WxRichTextCtrl_cycles->SetValue(print_all_cycles());
    (Normal) Output after adding edges (1,0),(1,2),(2,0): (Note that the insert function inserts the symmetricals too, this is a bidirectional graph):
    WxRichTextCtrl_sparse:
    Edge (1,0):STE=1. P(x-): None N(x+): (2,0) U(y-): None D(y+): (1,2)
    Edge (2,0):STE=1. P(x-): (1,0) N(x+): None U(y-): None D(y+): (2,1)
    Edge (0,1):STE=1. P(x-): None N(x+): (2,1) U(y-): None D(y+): (0,2)
    Edge (2,1):STE=0. P(x-): (0,1) N(x+): None U(y-): (2,0) D(y+): None
    Edge (0,2):STE=1. P(x-): None N(x+): (1,2) U(y-): (0,1) D(y+): None
    Edge (1,2):STE=0. P(x-): (0,2) N(x+): None U(y-): (1,0) D(y+): None
    WxRichTextCtrl_cycles:
    Graph cycle for edge (2,1)spanning tree root: 0)
    (0,2)->(2,1)<-(1,0)
    Graph cycle for edge (1,2):
    (0,1)->(1,2)<-(2,0)
    Now, also consider the normal output after just inputting edge (1,0):
    WxRichTextCtrl_sparse:
    Edge (1,0):STE=1. P(x-): None N(x+): None U(y-): None D(y+): None
    Edge (0,1):STE=1. P(x-): None N(x+): None U(y-): None D(y+): None
    WxRichTextCtrl_cycles:
    No cycles detected: Graph is a tree.
    ...and here''s the output, after just adding (1,0), that I get through running the program outside the IDE:
    WxRichTextCtrl_sparse:
    Edge (1,0):STE=1. P(x-): None N(x+): None U
    WxRichTextCtrl_cycles:
    No cycles detected: Graph is a tree.
    This is the first and only time that the first routine "works a bit", then, any output on both windows is nothing, emptiness.
    Here's some of the the code:
    Code:
    void Sparse_Array_GUIDlg::WxButton1Click(wxCommandEvent& event)
    {
     switch(WxRadioBox1->GetSelection())
     {
            case 1://Delete
                delete_edge(find_edge(WxSpinCtrl1->GetValue(),WxSpinCtrl2->GetValue()));
                break;
            case 0://Insert
                insert_edge(WxSpinCtrl1->GetValue(),WxSpinCtrl2->GetValue());
                break;
        }
        WxSpinCtrl_root->SetValue(validroot(WxSpinCtrl_root->GetValue()));//set root to a valid one
        create_spanning_tree(WxSpinCtrl_root->GetValue());
        create_all_cycles();
        WxRichTextCtrl_sparse->SetValue(print_all_edges());
        WxRichTextCtrl_cycles->SetValue(print_all_cycles());
    }
    Code:
    typedef struct pathmember * pp;
    typedef struct edge * ep;//Edge Pointer
    struct edge{
           int x,y;
           bool STE;
           pp p1,p2;
           ep prev,next,up,down;
    };
    struct nodetype{
           char STN;//(0:not STN)(1:STN, but (possibly) has neighbours that are not STN)(2:STN + neighbours=STN)
    //1 are nodes of current spanning tree level search. 2 are old, 0 are future.
           bool TN;//if false, this node doesn't exist
           int parent;
    };
    struct pathmember{
        pathmember * next;
        ep target;
    };
    Code:
    const char* print_edge(ep temp, bool longmode)
    {
           stringstream s;
           s.str("");//Initialization of s
           unsigned char x=2;
           if(longmode) s<<"Edge ";
           s<<"("<<temp->x<<","<<temp->y<<")";
           if(longmode) s<<":STE="<<temp->STE;
           if(longmode)
           {
               s<<".    P(x-): ";
               if(temp->prev) s<<"("<<temp->prev->x<<","<<temp->y<<")"; else s<<"None";
               s<<"  N(x+): ";
               if(temp->next) s<<"("<<temp->next->x<<","<<temp->y<<")"; else s<<"None";
               s<<"  U(y-): ";
               if(temp->up)   s<<"("<<temp->x<<","<<temp->up  ->y<<")"; else s<<"None";
               s<<"  D(y+): ";
               if(temp->down) s<<"("<<temp->x<<","<<temp->down->y<<")"; else s<<"None";
               s<<"\n";
           }
           return s.str().c_str();
    }
    Code:
    const char* print_all_edges()
    {
        int i,j;
        string s="";
        ep temp;
        for(i=0;i<30;i++)
        {
            temp=SparseArrayVertical[i];
            while(temp)
            {
                s+=print_edge(temp);
                temp=temp->next;
            }
        }
        if(s=="") return "Sparse Array is empty";
        return s.c_str();
    }
    Code:
    const char* print_cycle(ep i)
    {
        string s="Graph cycle for edge ";
        s+=print_edge(i,false);
        s+=":\n";
        //s+="\nPath 1/2: From joint to sentinel (forward):\n";
        do
        {
            s+=print_edge(i->p1->target,false);
            s+="->";
            i->p1=i->p1->next;
        }while(i->p1->next);
        s+=print_edge(i,false);
        //s+="Path 2/2: From joint to sentinel (backward):\n";
        /*do
        {
            s+="<-";
            s+=print_edge(i->p2->target,false);
            i->p2=i->p2->next;
        }while(i->p2->next);*/
        s+=reverse_path_print(i->p2);
        s+="\n\n";
        return s.c_str();
    }
    Code:
    const char* print_all_cycles(void)
    {
        int i,j;
        string s="";
        ep temp;
        for(i=0;i<30;i++)
        {
            temp=SparseArrayVertical[i];
            while(temp)
            {
                if(temp->p1)
                {
                    cout<<"Called: printcycle for edge: "<<print_edge(temp,false);
                    s+=print_cycle(temp);
                }
                temp=temp->next;
            }
        }
        if(s=="") return "No cycles detected: Graph is a tree.";
        return s.c_str();
    }

  9. #9
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Code:
    const char* function()
    {
    string s;
    
    // [...] do stuff
    
    return s.c_str();
    
    }
    This will fail. Not every time, but sometimes. This may well be the strange behaviour you see. The c_str() function will return a pointer to the chars held by "s". However, at the end of the scope (in this case, end of the function) s will be destroyed. Including all characters it held. So the value c_str() pointed to is no longer valid. The easiest way would be to convert all your functions to return a string object instead of const char*.
    Salem likes this.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  10. #10
    Registered User
    Join Date
    Nov 2011
    Posts
    22
    ...and it was that, indeed. What a newb I be. But the "sometimes" part made me not suspect anything like that! MANY THANKS!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. while runs foreverly
    By dhuan in forum C++ Programming
    Replies: 4
    Last Post: 08-26-2010, 11:41 PM
  2. Replies: 4
    Last Post: 09-12-2009, 02:10 PM
  3. This runs..but why not this. Help me to understand, please
    By polymatrix in forum C Programming
    Replies: 21
    Last Post: 07-22-2008, 03:16 AM
  4. wxdevC++
    By anirban in forum C Programming
    Replies: 13
    Last Post: 04-09-2007, 07:53 AM
  5. multiple runs of a program
    By unregistered in forum Linux Programming
    Replies: 5
    Last Post: 03-15-2002, 07:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21