Thread: Rusty with c++ need some help with errors involving pointers and stuff

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    - thats just ugly and more work than required and since its now almost 2 a.m. and i'm running on 2 hours of sleep definately feeling lazy :-P
    As you wish. I will not be helping you until you fix that. Global variables make your code more difficult to trace.

    - actually the assignment description says to call them that.... sure i doubt i'd lose points if i did use something else, but i've also got this algorithm memorized with pi, d, and f so works for me
    Okay, in that case you should at least provide comments to state their proper names.

    -doesn't matter for this class...
    As you wish. I will not be helping you until you fix that. Your lecturer chose C++ instead of Java, so write your C++ code like C++, not Java.

    -int option=0;
    while (option!=3)
    nope looks initialized before use to me :-P
    In your updated code, yes. That's good.

    It is quite simple: if you want help, do things correctly when asked to do so. If not, then as you have admitted, you are lazy and do not deserve help.

    EDIT:
    In fact, I suspect that the use of global variables is indirectly related to your current problem. You are simply having difficulty tracing the code yourself.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    well thats pretty cruel..... thanks for the help you did give me

    guess i'll hope someone else is willing to figure out why color[u->data]="gray"; is causing a seg fault, or i'll seek help elsewhere

    for now i desperately need sleep

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    For now, you desperately need to fix your problems. If you don't, you will not learn. This is C++, not Java. Welcome to C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    well thats pretty cruel.....
    Not really. If I were to start helping you any further, the first thing I would do is fix those problems so I can understand your code more easily.

    thanks for the help you did give me
    You're welcome.

    for now i desperately need sleep
    Yeah, rest is usually a good idea if you need it
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by JJJIrish05 View Post
    guess i'll hope someone else is willing to figure out why color[u->data]="gray"; is causing a seg fault
    What compiler are you using? Do you know how to use an interactive debugger? My guess is that you are either accessing color out of bounds (what is the value of u->data?), or u is NULL or points to some random address.

  6. #21
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    added the deletes to fix that stuff.....

    &u->data prints out 0 and u->data seg faults.... why?

    I'm using gcc on a linux machine to compile, never used a debugger

  7. #22
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by JJJIrish05 View Post
    &u->data prints out 0 and u->data seg faults.... why?
    Because u doesn't point to anything, it is 0. 0->data is what is causing your seg fault.

    I'm using gcc on a linux machine to compile, never used a debugger
    You should learn how to use gdb, the Gnu debugger.

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I won't testify as to which debugger is the best, but I prefer Visual Studio. Easy to setup, easy to get used to.
    No need to remember command lines or search for an appropriate gui for it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    If you require a graphical debugger under *nix, you can also use ddd, or Code::Blocks, which is cross-platform.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. returning pointers
    By spudval in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2007, 02:12 PM
  2. References vs Pointer vs copying and storing stuff in classes
    By Monkeymagic in forum C++ Programming
    Replies: 20
    Last Post: 09-01-2006, 09:40 AM
  3. kinda wierd stuff with pointers...
    By Noobwaker in forum C Programming
    Replies: 4
    Last Post: 04-17-2006, 02:21 PM
  4. delete and delete[]
    By Hunter2 in forum C++ Programming
    Replies: 13
    Last Post: 06-26-2003, 04:40 AM