Is it good for gdb to run successfully but not your program?
For some reason I am getting a seg fault with my malloc and it is really annoying.
Sorry if its bad code but I'm just learning C right now.
Is it good for gdb to run successfully but not your program?
For some reason I am getting a seg fault with my malloc and it is really annoying.
Sorry if its bad code but I'm just learning C right now.
First step is to stop casting the returns of malloc.
Oh and in C // is not a valid comment code
>Oh and in C // is not a valid comment code
I think that it is in C99.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
True in C99 it is but the chances that they are using a C99 compiler are...
It'll segfault if the file doesn't exist because the Load_List function will fclose( NULL ). Otherwise, it didn't segfault for me (GCC3.3, Linux).
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
arrrgg,
The file does exist but I'm limited to what compiler I'm allowed to use because it has to be able to run on the school lab computers.
uhhh, I'm // has been working fine for me, I wouldn't know why though.
Thanks for the help
Yeah, // works in all of my compilers: MSVC++7 (in a C project), DMC, GCC, etc...
It's pretty much standard now.
One major thing I noticed is the lack of proper error checking. Every malloc call needs to be checked for errors.
Since you mentioned the school's lab I'm gonna venture a guess that it is using a windows platform.
If that is correct then your path should be:
"\\stud\\rdonnell\\word"
no I'm on linux redhat 9.0
The reason I don't have error checking is because I'm just trying to get some basics out of the way. I will put it in but later.
Ok just wanted to make sure on the file system part
The thing is that malloc error checking and file opening error checking (which you do have) are of such importance you can't throw them to the side for later.
Granted they usally don't fail but the risk is too high.
BTW is the function In_File() important? You don't have it in the code.
Edit: moved the fclose into the if statement and it exit normally.
If the file exist, do you have the proper permissions?
Last edited by Thantos; 03-25-2004 at 10:19 PM.
Try just putting the "word" file in the same directory as the executable. Then you don't need to worry about paths.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
When do you think the most errors occur, during initial development or after the basics are out of the way?Originally posted by EvilBaby
no I'm on linux redhat 9.0
The reason I don't have error checking is because I'm just trying to get some basics out of the way. I will put it in but later.
"I'm building a rocket car and I've got the Saturn V engine installed. I'll add the brakes after I've got the engine basics tested. EvilBaby, you get the first test drive."
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
You might find lint to be helpful when trying to work a bug out.
Directly from the man page:
By the time I'm done with lint, there's barely a reason to turn to gdb.NAME:-
lint - a C program verifier
DESCRIPTION:-
lint attempts to detect features of the named C program files that are
likely to be bugs, non-portable, or wasteful. It also performs stricter
type checking than the C compiler. lint runs the C preprocessor as its
first phase, with the preprocessor symbol lint defined to allow certain
questionable code to be altered or skipped by lint. Therefore, this sym-
bol should be thought of as a reserved word for all code that is to be
checked by lint.