help on debugging

This is a discussion on help on debugging within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by matsp I'm even more confused. If you have a integer, it is stored in binary in the ...

  1. #46
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    Quote Originally Posted by matsp View Post
    I'm even more confused. If you have a integer, it is stored in binary in the computer. If it prints as 12, 14, 0x0c or something else is presentation. If you have a number you want to present in octal, then use the oct. You can not "convert an integer in decimal to octal", because integers are stored internally in the computer as binary. If you want to display an integer as binary, then do this:
    Code:
    std::string result;
    int x = 12;  // Or 012 if you want it to be octal. 0x12 for hex. 
    const int numdigits = 10;  // Number of bits you want to display. 
    for(i = 0; i < numdigits; i++)
    {
        result += ('0' + (x & 1)) + result;
        x >>= 1;
    }
    --
    Mats
    well i got mixed up !!! wait a minute , if its not conversion from decimal to octal and vice versa, how does the oct do the magic? it just gives me a number that is not the previous one any more, i mean , when i enter 10 as decimal , ( here i am the only one who knows the base , ) and when i use oct. teh output number will be 12 , which is to me an octal number in integer! so then it would be stored in memory just like "001 010" representing an octal value( i think). am i right?! so what do we call this process, ? we do arithmatics on these figures i mean scintific stuff works in different bases, so if this is not conversion , what is it?, !i mean , you know , well from what you ve mentioned, i gather, to the system teh binary matters, ! no octal or decimal or stuff. , when we are explicitly working with octal and stff, system works with binary anyway, but it represents as if it is octal! is it right?!!? ( exteremly confused! sorry for being stupid! i just dont understand!)
    Last edited by Masterx; 01-29-2009 at 07:36 AM.
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  2. #47
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    Quote Originally Posted by vart View Post
    Something like
    Code:
    std::string OcttoBin2(int n)
    {
        std::bitset<CHAR_BIT * sizeof(int)> bs(OcttoDec(n));
    
        std::stringstream test;
        test << bs;
        return test.str();
    }
    it calls octal to dec and then use the output to get the its binary form?!
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  3. #48
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you enter 10 (decimal) to a input operator, it will (unless you have specified otherwise) take it as a decimal number. It will be stored as 000...01010 internally in the computer. If you then print that using oct, it will come out in octal. The octal representation of 00...001010 is 12. So, the number stored in the integer is exactly the same whether you entered 0x0a, 012 or 10 [assuming the machine understands that 0x.. is hex, and 0... is octal, and not starting with 0 is decimal].

    Integers, no matter how they got into the computer, are stored as binary. You can choose, when you output them and when you input them, given the right input and output methods, to DISPLAY the number in different bases. But it doesn't really change the internal value of the number.

    To explain it a different way: We have a piece of wood, that happens to be two meters long. Now, we can express that as 2000 mm, 200 cm or 2m. Or as 6'6" or 78". But it's still the same piece of wood, whichever unit we describe it's length with. The same applies to displaying numbers in computers - we can use "any unit", but the actual number is the same either way.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #49
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    Quote Originally Posted by matsp View Post
    If you enter 10 (decimal) to a input operator, it will (unless you have specified otherwise) take it as a decimal number. It will be stored as 000...01010 internally in the computer. If you then print that using oct, it will come out in octal. The octal representation of 00...001010 is 12. So, the number stored in the integer is exactly the same whether you entered 0x0a, 012 or 10 [assuming the machine understands that 0x.. is hex, and 0... is octal, and not starting with 0 is decimal].

    Integers, no matter how they got into the computer, are stored as binary. You can choose, when you output them and when you input them, given the right input and output methods, to DISPLAY the number in different bases. But it doesn't really change the internal value of the number.

    To explain it a different way: We have a piece of wood, that happens to be two meters long. Now, we can express that as 2000 mm, 200 cm or 2m. Or as 6'6" or 78". But it's still the same piece of wood, whichever unit we describe it's length with. The same applies to displaying numbers in computers - we can use "any unit", but the actual number is the same either way.

    --
    Mats
    thanks thanks thanks , thanks ! i just got it dude, im really amazed! so thats how it is done down there !
    iwont forget this . really tanx ..Dear Mats. you taught me couple of new things!
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  5. #50
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    hello again , ive almost completely revised the project. removed almost all of the C style string variables, but still i get that error at the end of the program! !
    when i pressed debug, the program terminated, and then it pointed at the line: !

    Code:
      OurString = (*usrstr_it).second;
    in this function.:


    Code:
     int CLA::Fetch()
            {
                    if (cntt == 0)
                    usrstr_it = StringCollector.begin();
    
                    while ( usrstr_it != StringCollector.end() && check2) 
                    {
                            if (cntt != 0) //for first element.after a successful loop, 
    //this condition becomes true and next string will be fetched.
                            usrstr_it++;
    
                            OurString = (*usrstr_it).second; //get the string.
                            if (OurString == "exit" ||OurString == "Exit" ||OurString =="EXIT")
                            {
                                   EXIT = true;
                                    break;
                            }
    
                            cntt++;
    
                            check = 1;      //this  indicates fetch is running and should be running.
                            check2 = false; //geting away from infinite loop.(gets out of the loop when we have he string.
    
    
                    }
                    if ( usrstr_it == StringCollector.end() || EXIT )
                                 check = 0; //end of loop . end of stringcollector, the end of string processing
                    if (check ==0 )
                    condition = false;
    
    
                    return check;
                
                
    
            }//end of Fetch();
    and again it indicates that the loop in main.cpp has a probelm :
    ive taken a screenshot , so that you can see the actual line !!

    well i dont know what to do now, heres the new source code !:
    newCLA.zip

    pic2
    pic1
    pic3
    hope you can help me with it.
    Last edited by Masterx; 01-30-2009 at 09:46 AM.
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  6. #51
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    any help!
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  7. #52
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
                            usrstr_it++;
    
                            OurString = (*usrstr_it).second; //get the string.
    After incrementing the . . . well, I'm assuming it's an iterator . . . how do you know it's still valid? You should probably check to make sure it's still in range after you increment it.

    [edit] That's pretty funny that after some 12 hours, we both post at exactly the same time (I didn't see your post) . . . [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #53
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    Quote Originally Posted by dwks View Post
    Code:
                            usrstr_it++;
    
                            OurString = (*usrstr_it).second; //get the string.
    After incrementing the . . . well, I'm assuming it's an iterator . . . how do you know it's still valid? You should probably check to make sure it's still in range after you increment it.

    [edit] That's pretty funny that after some 12 hours, we both post at exactly the same time (I didn't see your post) . . . [/edit]
    thanks dear dwks,
    ( about post :yeah i didnt even notice that)

    ----------------------
    edited: Got it , thanks im checking it now!.
    ===============================
    edited. it works like a charm now.
    Last edited by Masterx; 01-30-2009 at 09:58 AM.
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  9. #54
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    OHHH GOD , Oh GOD , DWKS , YOU ARE AN ANGLE MAN, its Gone , i cant BEleive it , it just happened ! it worked .!! i realllly dont know how to thank you .to thank you alll Dears , my treasures ! ( deeply touched !)

    A big big big enormous Thank to you all specially dear DWKS!
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  10. #55
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    But if userit is just before end userit++ will put it AT end. That is not a valid place to look at the content.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #56
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    Quote Originally Posted by matsp View Post
    But if userit is just before end userit++ will put it AT end. That is not a valid place to look at the content.

    --
    Mats
    yeah, so what should i do ? nothing crosses my mind now to fix this!!
    at the moment , ill try putting it lets say at the end!. i ll you what happens.(
    but if is not right , ( as it is not right! ) how come the program just works fine?!)
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  12. #57
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    changed to :
    Code:
     int CLA::Fetch()
            {
                   
                    if (cntt == 0)
                    usrstr_it = StringCollector.begin();
    
                    while ( usrstr_it != StringCollector.end() && check2) 
                    {
                            if (cntt != 0) /*for first element.after a successful loop,
                                                this condition becomes true and next string will be fetched.*/
    
                            if (usrstr_it == StringCollector.end())
                            {
                                    break;
                            }
                            OurString = (*usrstr_it).second; //get the string.
                            if (OurString == "exit" ||OurString == "Exit" ||OurString =="EXIT")
                            {
                                   EXIT = true;
                                    break;
                            }
    
                            cntt++;
    
                            check = 1;      //this  indicates fetch is runing and should be running.
                            check2 = false; //geting away from infinit loop.(gets out of the loop when we have he string.
    
                            usrstr_it++;
                    }
                    if ( usrstr_it == StringCollector.end() || EXIT )
                                 check = 0; //end of loop . end of stringcollector, the end of string processing
                    if (check ==0 )
                    condition = false;
    
    
                    return check;
    and progarm still works fine ! ( i think its better and more secure than before ! many thanks to you Dear Mats.)
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-C++: Problems with Breakpoint Debugging
    By Thileepan_Bala in forum C Programming
    Replies: 1
    Last Post: 01-17-2008, 10:48 AM
  2. Problem in debugging in Eclipse
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 08-21-2007, 10:53 AM
  3. Debugging Dev C++
    By tuurb046 in forum Tech Board
    Replies: 10
    Last Post: 08-16-2007, 01:51 PM
  4. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 08:35 PM
  5. debugging directx apps
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 08-16-2003, 09:56 AM

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