home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12618 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  999 b 

  1. Path: sparky!uunet!decwrl!world!ksr!jfw
  2. From: jfw@ksr.com (John F. Woods)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: problems with atof()
  5. Message-ID: <15055@ksr.com>
  6. Date: 21 Aug 92 14:45:46 EDT
  7. References: <1992Aug20.125252.3451@dxcern.cern.ch>
  8. Sender: news@ksr.com
  9. Lines: 22
  10.  
  11. nilo@atdigarfield.cern.ch (Operator) writes:
  12. > I have a problem withe the atof() function, you know string to double 
  13. >conversion. 
  14. >    #include <stdio.h>
  15. >    #include <ctype.h>
  16. >    main()
  17. >     {
  18. >       double a[2];
  19. >       char *b="-.345"
  20. >       printf("this is b : %f  %s \n",atof(b),b);
  21.  
  22. >       a[0] = atof(b);
  23.  
  24. You have not declared atof() before using it, therefore you have told the
  25. compiler that it returns an int.  It does not, as you know.  You lied to the
  26. compiler, and it extracted its revenge.
  27.  
  28. Either add a declaration somewhere appropriate, like
  29.     double atof( /* char *string */ );  /* for ANSI C, uncomment the
  30.                          * parameter declaration */
  31. or (if you have ANSI C) you can add
  32.     #include <stdlib.h>
  33.