Click to See Complete Forum and Search --> : my code


kakuustaad
07-22-2002, 02:50 PM
hi can you please check my code at
www.cyberspace.org/~learn/index.html
and tell me whats wrong with it .. when i try to modify some record it add a new one at the add of the file ,(instead of modifying it )

and yaaa dont ask me INCLUDE WHAT ? html seem to eat up my angel braket stuffs

truls
07-22-2002, 04:17 PM
My guess is that since you open the file as "ab+", meaning 'open or create for reading and writing at end of file', that's basically what you get.Try using "rb+" instead. You should also check the validity of fp after opening the file.

T.

NecroLin
07-22-2002, 04:22 PM
As far as the HTML is concerned you may want to use:

#include <stdio.h>

< is the HTML code for the less than sign and > the greater than sign.;)

As far as your program that has to wait till I get home...my boss sits right behind me....:(

mingshun
07-24-2002, 09:44 AM
Originally posted by kakuustaad
hi can you please check my code at
www.cyberspace.org/~learn/index.html
and tell me whats wrong with it .. when i try to modify some record it add a new one at the add of the file ,(instead of modifying it )

and yaaa dont ask me INCLUDE WHAT ? html seem to eat up my angel braket stuffs

First of all, you should include #include <stdlib.h> for your
headers. Are you compiling C in Unix?

You should use the append mode for fopen if you want to
add something to the end of a file; not the write binary mode.
In Unix, you can "man -s3c fopen" to lookup in details for the
usage of append mode.

Hope this help.

kakuustaad
07-25-2002, 04:07 AM
man i dont want to add i want to modify .. want to overwrite the old record with the new one .. why dont you guys try to compile and check what am i trying to point .. add some records and then try to use the modify function

kakuustaad
07-25-2002, 04:09 AM
man i dont want to add i want to modify .. want to overwrite the old record with the new one .. why dont you guys try to compile and check what am i trying to point .. add some records and then try to use the modify function .. and i have included the stdlib header file :P

truls
07-25-2002, 06:22 AM
It works if you do a fclose and fopen at the beginning of the mod_rec function. I'm not sure why you have to close the file though. I've tried a fflush, but that did not do it. Strange...

kakuustaad
07-25-2002, 09:26 AM
)-: i tried my best .. but sill not working .. i have opened the file in every function seperately according to you .. but still its not working .. can you pplz mail me the code if you can get it to work .. here is my link for my progs with new changes
www.cyberspace.org/~learn/prog.c
and a html version
www.cyberspace.org/~learn/inex.html
:P

kakuustaad
07-25-2002, 09:28 AM
)-: i tried my best .. but sill not working .. i have opened the file in every function seperately according to you .. but still its not working .. can you pplz mail me the code if you can get it to work .. here is my link for my progs with new changes
www.cyberspace.org/~learn/prog.c
and an html version
www.cyberspace.org/~learn/index.html

and by the way what is this grasshopper and senior grasshopper + juniour grasshopper stuff .. which always appear with your username ?

truls
07-25-2002, 11:26 AM
I changed your open call arguments to use binary mode (change "r+" to "r+b", "a+" to "a+b"), and then everything worked wonders. That's the only change I made to your code.

BTW: I get a weird "unary minus operator applied to unsigned type" warning on the fseek() call, some Microsoft weirdness?

I tried your original code with GCC, and that worked off the bat, so I think this is some Microsoft compiler weirdness.