Thread: Can't compile on the other compiler

  1. #1
    Banned
    Join Date
    May 2003
    Posts
    124

    Can't compile on the other compiler

    A Program runs properly in my compiler and prints the right results, but can't compile in the compiler of a judge. The compiler of the judge says the following:

    program.c: In function `int main()':
    program.c:25: implicit declaration of function `int ltoa(...)'
    --> 25: ltoa( a, string, 10);

    I can't understand where the problem is.

    The only libraries i use is <stdio.h> and <stdiib.h>.
    Is there something wrong with my "ltoa" statement?

    i would really appriciate it if you could help me.

  2. #2
    Banned
    Join Date
    May 2003
    Posts
    124
    Sorry, i mean <stdlib. h>

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Is there something wrong with my "ltoa" statement?
    Yes, it's not a standard function. You shouldn't expect it to work on another compiler. However, an alternative solution that is standard is to use sprintf:
    Code:
    sprintf(string, "%ld", a);
    My best code is written with the delete key.

  4. #4
    Banned
    Join Date
    May 2003
    Posts
    124
    Thanks
    1)Is it possible for their compiler not to have <stdlib.h> library? Remember it is a judge.

    2)What’s the difference between “sprintf” and ”ltoa”

  5. #5
    Banned
    Join Date
    May 2003
    Posts
    124
    1)Is it possible for their compiler not to have <stdlib.h> library? Remember it is a judge.
    2)What’s the difference between “sprintf” and ”ltoa”

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    148
    Originally posted by AProg
    1)Is it possible for their compiler not to have <stdlib.h> library? Remember it is a judge.
    No,stdlib.h is standard.

    2)What’s the difference between “sprintf” and ”ltoa”
    sprintf is standard,itoa not.
    itoa is a very simple function,converts int to string.
    sprintf is very general,writes formatted data to a string (all kind of).
    Btw. don't use sprintf if you have snprintf (notice the 'n').
    sprintf is a buffer overflow candidate.

  7. #7
    Banned
    Join Date
    May 2003
    Posts
    124
    Why shouldn't i use sprintf if i have snprintf?
    What is a buff?

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    A buffer overflow is when more data is written to the string than it can hold. Like if you had char x[10] and tried to write 15 characters to it.

    snprintf allows you to specify the most data the buffer can hold. If more is going to be written, it is truncated.
    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

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >1)Is it possible for their compiler not to have <stdlib.h> library? Remember it is a judge.
    Yes, it is, the C standard only specifies that a freestanding implementation supply <float.h>, <limits.h>, <stdarg.h>, and <stddef.h>. Though for a contest I would consider it very unlikely that you would have such restrictions.

    >Btw. don't use sprintf if you have snprintf (notice the 'n').
    Since standard conformance seems to be a biggie in this program, keep in mind that snprintf is only standard in C99 implementations. Otherwise its usage is not portable.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using DXUT with Borland 5.5 free compiler
    By Jedi Nescioquis in forum Game Programming
    Replies: 7
    Last Post: 02-11-2009, 12:04 PM
  2. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  3. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  4. My Dev compiler won't compile
    By Unregistered in forum C++ Programming
    Replies: 22
    Last Post: 05-04-2002, 06:37 PM
  5. Special Compiler for win app's
    By Unregistered in forum Windows Programming
    Replies: 19
    Last Post: 04-26-2002, 03:52 PM