Ask your own question, for FREE!
Computer Science 39 Online
OpenStudy (anonymous):

hello all any 1 care to debug my code......thanks it's in c

OpenStudy (anonymous):

OpenStudy (anonymous):

@calmchessplayer

OpenStudy (anonymous):

@NeThWa

OpenStudy (anonymous):

Not really that is what they made debuggers for lol ;-p

OpenStudy (anonymous):

oh really :-/ thanks for ur time @MathDoodler

OpenStudy (anonymous):

Doing it now !

OpenStudy (anonymous):

Ahem...way too many warnings...first try to get rid of them, then post the code !

OpenStudy (rsmith6559):

Your print() function seems to have the most logical problems. The first while statement in the search() function seems unnecessary. Other than that it needs work, but it doesn't look too bad.

OpenStudy (anonymous):

yea i got warnings but it does compile but does not execute properly......

OpenStudy (anonymous):

yea two while's are not necessary....forgot to remove one of em

OpenStudy (anonymous):

heck I don't even think you can use a function as a parameter in a switch statement unless its returning a variable and even then you would need something like var returndata = create(); with returndata variable being used in the switch parameter wich would probably never work because the switch isn't going to stop and wait for data to be returned before puking

OpenStudy (anonymous):

@calmchessplayer check this put

OpenStudy (anonymous):

yeah that shold work 1 for print 2 for scan

OpenStudy (anonymous):

nd it shud work for the that dbs program too :-/

OpenStudy (anonymous):

yeah its basic programming should be same across multiple languages....if you know the core stuff really well and OOP concepts fairly well you can use core programming skills across mulitple languages just syntax will be a little diffrent but thats why we have API

OpenStudy (anonymous):

c is not object oriented

OpenStudy (anonymous):

really I never noticed

OpenStudy (anonymous):

There's a problem in the getnode function. You check the head variable (through tem) to see if it has a next item, but what if head does not contain a node yet? I'll have a look through the rest of the code. I'll get back to you later.

OpenStudy (anonymous):

head is a pointer r8....like get node is to make a node an attach it in the end @slotema

OpenStudy (anonymous):

True, but I mean something different. When your program starts, head is assigned the value NULL. That's its value the first time you call getnode. You then try to see if head->next == NULL, but since head is still NULL, it cannot have a field called `next' since it does not exist yet. That's what is giving me a Segmentation Fault when I try to create a db.

OpenStudy (anonymous):

ok thanks i got u

OpenStudy (anonymous):

thanks @slotema it's an improvement but it still doesnt work

OpenStudy (anonymous):

First off, there's something wrong with your struct definition. You refer to `struct node', but that does not exists yet. If you want to read a word from the user, it's probably better to use %s, instead of %[^\n] (though %s stops reading at the first white-space). You second while loop in the search function checks if temp has a next item. What if a node does not have a next item? You'll still want to compare its name with the name you're searching for. That's not happening right now, since that node is ignored. As is mentioned by rsmith6559 you could do without the first loop here. Suppose that search does not find a node, what happens then? You do print a nice error message that no node can be found, but you will need to inform the edit function somehow. That function should know that no node was found so that it won't try to edit anything. As for the print function: you ask for a file name, but you never read any user input afterwards. The node `temp' is just a pointer and not assigned any value before you use it. The fprintf function also need the file handle (fp) as one of its arguments. You also try to print an integer with "&d" instead of "%d". You're almost there. If you fix these problems, I think your code should work the way it should. Don't be discouraged, making mistakes is a great way to learn and it happens to anyone who tries to learn programming. Some final remarks: Try to be consequent with your indentation, it makes your code better readable. Try to comment your code. Explain what you are doing (unless it's obvious), but also why you are doing something. Finally, don't just ignore warnings because they're warnings. Especially when your program is not working the way it should. For example, the problem with the fprintf was mentioned in the warnings for me. It's general good practice to try to write code that does not produce warnings.

OpenStudy (anonymous):

yea thanks it a backward slash i forgot that.......thank u :))

OpenStudy (anonymous):

no is it [^\n]?

OpenStudy (anonymous):

You can use [^\n], but it can cause some problems. See for example http://stackoverflow.com/questions/6083045/scanf-n-skips-the-2nd-input-but-n-does-not-why I'd still suggest to use %s (unless you really want to include white-spaces in the names you're reading).

OpenStudy (anonymous):

yea thanks but it doesnt work......like it prints both the statements at the same time that name n qty thing....may be i l use %s....

OpenStudy (anonymous):

For that, read the stackoverflow link I gave you. The second answer explains what the problem is quite nice.

OpenStudy (anonymous):

wow thanks

OpenStudy (anonymous):

aww ther's still a prob with print function.....

OpenStudy (anonymous):

what kind of problem?

OpenStudy (anonymous):

idk.....i added a scand but exe file likes stops nd a error window pops out

OpenStudy (anonymous):

and what does the error window say?

OpenStudy (anonymous):

wait i think the format of fprintf it's wrong i m verifying it

OpenStudy (anonymous):

hey @slotema can u plz compile it n c...i used codeblox

OpenStudy (anonymous):

sure, just give me your updated source code.

OpenStudy (anonymous):

ok jus a min

OpenStudy (anonymous):

OpenStudy (anonymous):

two things: if you want to read something into name with scanf, you'll need to put an `&' in front of it. Secondly, you use "&d" to print an integer. That should be "%d".

OpenStudy (anonymous):

The last fprintf is also missing the file handle.

OpenStudy (anonymous):

fprintf(fp,"%d,%s,%f",i,temp->name,temp->qty); this 1 is correct r8?

OpenStudy (anonymous):

looks fine

OpenStudy (anonymous):

yea but i got issues with that.....

OpenStudy (anonymous):

Have you assigned a value to temp already? If so, what issues?

OpenStudy (anonymous):

the same pop up window ....dbs.exe stopped working

OpenStudy (anonymous):

wow even search s got issues checking scanf's

OpenStudy (anonymous):

There were two things I noticed that might cause a crash: when you use a scanf to read a string, you'll need to put an `&' in front of the variable you want the result in. Secondly, in the print loop, you use the temp variable, but that variable is never assigned a value.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
chatAI: Happy Easter!
48 minutes ago 0 Replies 0 Medals
danielfootball123: HAPPY EASTER!!!!
45 minutes ago 8 Replies 0 Medals
ShadowKid3: I drew Leon again (used suggestions from last art post) so Leon v2 :D
5 minutes ago 4 Replies 0 Medals
Puck: for all you amazing people
43 minutes ago 3 Replies 2 Medals
Breathless: update on drawing.
3 hours ago 12 Replies 5 Medals
ShadowKid3: what are examples of a class three lever?
1 day ago 3 Replies 2 Medals
alphaXtiger: Help pls
2 days ago 3 Replies 1 Medal
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!