Skip to main content
gamedev.net
🔒 Locked

Having problems...

Started by GoldenViper_LO 6 replies 1.1k views
Original Post
GoldenViper_LO
GoldenViper_LO
Hey there, I'm new to C and I am doing something that my book says to do. I keep getting an error that says "Call to undentifed function "exit" in function main(int,char * *)" Here's where it says the error is... { fprintf(stderr, "\nProper Usage is: " ); fprintf(stderr, "\n\nPRINT_IT filename.ext\n" ); exit(1); } Please lemme know what to do, thanks. -Russ
xllx_relient_xllx
xllx_relient_xllx
Are you sure you're including the C standard library "stdlib.h"?

...
"#include "stdlib.h"
GoldenViper_LO
GoldenViper_LO
I use "#include <stdio.h>" That's what the book says too, I'm so confused...
Drew_Benton
Drew_Benton
Quote:
Original post by GoldenViper_LO
I use "#include <stdio.h>" That's what the book says too, I'm so confused...


You need to use "stdlib.h", not "stdio.h" as xllx_relient_xllx has said to get access to the exit function. MSDN linky
#include <stdio.h>#include <stdlib.h>int main( int argc ,char** argv ){   fprintf(stderr, "\nProper Usage is: " );   fprintf(stderr, "\n\nPRINT_IT filename.ext\n" );   exit(1);}
Conner McCloud
Conner McCloud
Any library functions that you want to call are defined in specific files. You have to include these files. The <stdio.h> gives you the fprintf functions, but not exit. I believe that is defined in <stdlib.h>, so add #include <stdlib.h> right after your #include <stdio.h>

However, exit is unneccessary from within main. That is used to immediately exit the program, no matter where you are. Within main, this functionality is provided by return. exit(5); is identical to return 5;. The difference between the two options is that exit exits the program, but return only exits the current function. Since nothing calls main [that you need to worry about], exiting the current function also exits the program.

CM
xllx_relient_xllx
xllx_relient_xllx
I would also like to add something else..

The diffrence between <stdlib.h> and "stdlib.h" is not such a matter of importance. Because, the former tells the compiler to look for the stdlib.h library in the compilers main library folder (or something of that sort) first, and, the latter tells it to look in the programs current directory (where your compiled files reside) first.

In light of that. I think you should, like most everyone else, use < .. > for standard library's and " .. " for the ones you create.

BTW: I actually meant to use < .. > in my first example =)
relient

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.