Like Tree3Likes

help for debugging my code

This is a discussion on help for debugging my code within the C Programming forums, part of the General Programming Boards category; hello can anyone help me with debugging my code that I'v used linked list in it? if yes tell me ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    17

    help for debugging my code

    hello

    can anyone help me with debugging my code that I'v used linked list in it?

    if yes tell me to put my code here???!!!

    it's my homework and I should submit it till next 2 hours.

    thanks!

  2. #2
    Registered User
    Join Date
    Dec 2012
    Posts
    289
    if you wanted help, you should have already posted the code

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    2,195
    Crossfire speaks true. Use code tags when posting your code. Two hours is kind of tight to get decent help with your problem and apply the advice to fix your code - you should try to be more prepared, for your own benefit.

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    17
    In this program we should read some data from some files that i attached 4 of them in linked lists and then use that data:

    i asked first because my code is not short/

    Ithink my storing data is incorrect;bodies please help!
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    17
    I use some printf instruction(printf("ok") to find where the first problem happens

    I know that i put my code late because i thought i can do it correctly,but ...

  6. #6
    Registered User
    Join Date
    Dec 2012
    Posts
    289
    Can't find include file "location2.h"

  7. #7
    Registered User
    Join Date
    Jan 2013
    Posts
    17
    excuse me i forgot to put these files

    please rename location.h to location2.h!!
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,427
    EDIT: I was busy writing this when you posted the location files, so disregard that part. The rest, however, stands.
    EDIT 2: Removed unnecessary compiler error messages

    Here's what I get when I compile your program:
    Code:
    $ make foo
    gcc -Wall -Wunreachable-code -ggdb3  -lm -lpthread  foo.c   -o foo
    foo.c:2:21: error: windows.h: No such file or directory
    foo.c:4:19: error: conio.h: No such file or directory
    foo.c:5:23: error: location2.h: No such file or directory
    foo.c: In function ‘main’:
    foo.c:55: error: ‘HANDLE’ undeclared (first use in this function)
    foo.c:55: error: (Each undeclared identifier is reported only once
    foo.c:55: error: for each function it appears in.)
    foo.c:55: error: expected ‘;’ before ‘hStdout’
    foo.c:56: error: ‘hStdout’ undeclared (first use in this function)
    foo.c:56: warning: implicit declaration of function ‘GetStdHandle’
    foo.c:56: error: ‘STD_OUTPUT_HANDLE’ undeclared (first use in this function)
    foo.c:58: warning: implicit declaration of function ‘init_console_functions’
    foo.c:254: warning: suggest parentheses around assignment used as truth value
    foo.c:256: warning: suggest parentheses around assignment used as truth value
    foo.c:258: warning: suggest parentheses around assignment used as truth value
    foo.c:297: warning: implicit declaration of function ‘clrscr’
    foo.c:353: warning: suggest parentheses around assignment used as truth value
    foo.c:355: warning: suggest parentheses around assignment used as truth value
    foo.c:357: warning: suggest parentheses around assignment used as truth value
    foo.c:438: warning: suggest parentheses around assignment used as truth value
    foo.c:440: warning: suggest parentheses around assignment used as truth value
    foo.c:442: warning: suggest parentheses around assignment used as truth value
    foo.c: In function ‘Drawing_mushroom’:
    foo.c:486: error: ‘HANDLE’ undeclared (first use in this function)
    foo.c:486: error: expected ‘;’ before ‘hStdout’
    foo.c:487: error: ‘hStdout’ undeclared (first use in this function)
    foo.c:487: error: ‘STD_OUTPUT_HANDLE’ undeclared (first use in this function)
    foo.c:489: warning: implicit declaration of function ‘gotoxy’
    foo.c:490: warning: implicit declaration of function ‘SetConsoleTextAttribute’
    foo.c: In function ‘Drawing_flower’:
    foo.c:502: error: ‘HANDLE’ undeclared (first use in this function)
    foo.c:502: error: expected ‘;’ before ‘hStdout’
    foo.c:503: error: ‘hStdout’ undeclared (first use in this function)
    foo.c:503: error: ‘STD_OUTPUT_HANDLE’ undeclared (first use in this function)
    ...
    make: *** [foo] Error 1
    1. I'm guessing most of the "undeclared" issues are due to you not providing us with location2.h and the fact that I don't have windows.h and conio.h since I use Linux.
    2. All the "suggest parentheses" ones seem to be because you are using = instead of ==.
    3. fflush(stdin) results in undefined behavior. Read this link.
    4. Your while loop around line 98 while ((fscanf(...) != EOF) is wrong, don't check against EOF. You need to check whether it successfully read a char. fscanf returns the number of things it successfully scanned (1 in your case). Try while (fscanf() != 1).
    5. You don't check all your error conditions (e.g. malloc, fopen). Sometimes, when you encounter a critical error, like malloc failing, you continue your program anyway, begging for a seg fault.
    6. You use lots of printf's for debugging, but printf is buffered, so your debug "ok" prints might not show up when you expect them, leading you to think the problem is elsewhere. You need to print a newline, flush stdout, or use stderr for debug prints.
    7. It's too late now, but you really should have broken your main function up into more smaller functions, it would be much easier to debug that way.
    8. There's lots more little things, but you wont have the time, and I don't feel like reading through every line of your code.

    You say you think your "storing" code is wrong. What code, exactly, would that be? Nowhere in your comments, or in the name of functions or variables, do you use the word storing, so I can't locate the "storing" code. Also, tell us exactly what is wrong with it. Does the program crash? Does it run but give strange output? Does it "freeze"? We need more info.
    Last edited by anduril462; 01-08-2013 at 10:42 AM.

  9. #9
    Registered User
    Join Date
    Jan 2013
    Posts
    17
    I compile it with visual studio 2010 and it does not have any compile error.
    I put location2.h in previous post in name location.h and i asked you to rename it.
    for 2nd point i did not understand.
    I deleted some of that printf instruction but the problem is in same place i will say.

    with "storing" i meant reading data from files and save them in correct location.in line 91 i started to read data and store them.

    i want you to read the part that is related to reading and storing data and find my logical mistakes (maybe like memory problems)
    i think compiling it is not nessesary and i think its enough to read lines 81-196 and think about the logic of them.

    thanks!!

  10. #10
    Registered User
    Join Date
    Jan 2013
    Posts
    17
    see these pictures.
    Attached Images Attached Images   

  11. #11
    Registered User
    Join Date
    Jun 2011
    Posts
    2,195
    If you don't have any compiler warnings or errors, you need to find a way to increase the warning/error level.

    Code:
    Phase4.cpp||In function 'int main()':|
    Phase4.cpp|254|warning: suggest parentheses around assignment used as truth value|
    Phase4.cpp|256|warning: suggest parentheses around assignment used as truth value|
    Phase4.cpp|258|warning: suggest parentheses around assignment used as truth value|
    Phase4.cpp|353|warning: suggest parentheses around assignment used as truth value|
    Phase4.cpp|355|warning: suggest parentheses around assignment used as truth value|
    Phase4.cpp|357|warning: suggest parentheses around assignment used as truth value|
    Phase4.cpp|438|warning: suggest parentheses around assignment used as truth value|
    Phase4.cpp|440|warning: suggest parentheses around assignment used as truth value|
    Phase4.cpp|442|warning: suggest parentheses around assignment used as truth value|
    obj\Debug\Phase4.o||In function `main':|
    Phase4.cpp|58|undefined reference to `init_console_functions()'|
    Phase4.cpp|297|undefined reference to `clrscr()'|
    obj\Debug\Phase4.o||In function `Z16Drawing_mushroomiiii':|
    Phase4.cpp|489|undefined reference to `gotoxy(int, int)'|
    Phase4.cpp|492|undefined reference to `gotoxy(int, int)'|
    Phase4.cpp|496|undefined reference to `gotoxy(int, int)'|
    obj\Debug\Phase4.o||In function `Z14Drawing_floweriiii':|
    Phase4.cpp|505|undefined reference to `gotoxy(int, int)'|
    Phase4.cpp|508|undefined reference to `gotoxy(int, int)'|
    Phase4.cpp|511|more undefined references to `gotoxy(int, int)' follow|
    ||=== Build finished: 8 errors, 9 warnings ===|
    The "undefined references" is due to my compiler/libraries not supporting those functions, so I can't run your code.

    What you should be focusing on, to start, are the warnings up top. These indicate errors of this type:

    Code:
    /* you typed this: */
    
    if(x = y) /* incorrect! */
    
    /* ...when you meant to type this: */
    
    if(x == y)

  12. #12
    Registered User
    Join Date
    Jan 2013
    Posts
    17
    can you tell me where such this mistake has been made??in witch lines?

    function gotoxy in my program prints in coordinate x,y

    i told that if you want to help me it's not necessary to run my program , just think about the logic of my program specially in lines 81-196

    thanks!

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Re - post #10
    You should select option 3 - "Debug program".

    That will drop you in the debugger, pointing at the offending line of code.

    From there, you examine relevant variables, and try to construct (in your head) how the program got into that state.
    When you understand that, you can set about fixing it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  14. #14
    Registered User
    Join Date
    Jan 2013
    Posts
    17
    I meant which

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Name:  Screenshot at 2013-01-08 18:56:33.png
Views: 47
Size:  30.1 KB
    By my estimation, times up!
    Put down your keyboard, step away from the mouse.

    FYI, rolling into a forum with only hours to go and 100's of lines of code to look at is seldom productive.

    Try to leave more time (at least a day) before waiting to post when you're stuck.

    It also helps to write AND test as you go.
    A development process
    Expecting the whole thing to work right at the last minute is folly.
    Matticus likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Debugging Code
    By husslela2 in forum C Programming
    Replies: 14
    Last Post: 03-24-2010, 02:56 PM
  2. Replies: 1
    Last Post: 03-10-2010, 10:28 AM
  3. Need help debugging my code
    By lala123 in forum C Programming
    Replies: 36
    Last Post: 03-17-2008, 04:47 PM
  4. Need help in debugging this code
    By jaggesh in forum C Programming
    Replies: 4
    Last Post: 02-09-2008, 07:47 AM
  5. debugging code
    By DeViLs_SouL in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2001, 12:34 PM

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