Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7052217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:21:25+00:00 2026-05-28T03:21:25+00:00

Calling strtof with a floating point number runs fine on my local machine but

  • 0

Calling strtof with a floating point number runs fine on my local machine but on the school’s servers strtof always returns 0.000000. I checked to see if there was anything stored in errno since a 0 should mean an error, but it says success. Does anyone have an idea why this might be?

Here is the code.

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("%f\n", strtof(argv[1],0));
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:21:26+00:00Added an answer on May 28, 2026 at 3:21 am

    Short version: compile with -std=gnu99 or -std=c99. Explanation follows.

    I’ve reproduced a similar “problem” on my own box. However, when I try to compile:

    # gcc -Wall -o float float.c
    float.c: In function 'main':
    float.c:6: warning: implicit declaration of function 'strtof'
    float.c:6: warning: format '%f' expects type 'double', but argument 2 has type 'int'
    

    So I looked at the man page for strtof(), and it says:

    SYNOPSIS
       #include <stdlib.h>
    
       double strtod(const char *nptr, char **endptr);
    
       #define _XOPEN_SOURCE=600   /* or #define _ISOC99_SOURCE */
       #include <stdlib.h>
    
       float strtof(const char *nptr, char **endptr);
       long double strtold(const char *nptr, char **endptr);
    

    What that means is that one of those values has to be #defined before including stdlib.h. However, I just recompiled with -std=gnu99, and that defines one of those for me and it works.

    # gcc -std=gnu99 -Wall -o float float.c
    # ./float 2.3
    2.300000
    

    Moral: always compile with -Wall. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Calling std::count_if(vec.begin(), vec.end(), std::bind2nd(std::ptr_fun(foo), 17)) works fine with bool foo(int, int), but I can't
Calling an asp.net mvc3 controller method which returns the results fine (list of an
Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
Calling getActionBar returns null . This has been frequently reported so I've made sure
Calling MyPanel.Panel1.Hide(); or MyPanel.Panel2.Hide(); simply hides the controls inside the panel... but I want
Calling concat on vectors returns a list. Being a total noob I would expect
Calling a Lua function from C is fairly straight forward but is there a
Calling IEnumSTATURL::Next within my application returns E_UNEXPECTED(0x8000FFFF) instead of S_OK . Sadly, that particular
When calling Response.Cookie.Add(new HttpCookie(MyCookie, objValue)); where does the cookie saved? on Client Machine or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.