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!
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!
if you wanted help, you should have already posted the code
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.
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!
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 ...
Can't find include file "location2.h"
excuse me i forgot to put these files
please rename location.h to location2.h!!
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:
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.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
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 11:42 AM.
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!!
see these pictures.
If you don't have any compiler warnings or errors, you need to find a way to increase the warning/error level.
The "undefined references" is due to my compiler/libraries not supporting those functions, so I can't run your code.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 ===|
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)
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!
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 meant which
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.
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.