Advertisement

08.04.2006 at 01:01PM PDT, ID: 21943972
[x]
Attachment Details

atof() Problem Converting String into a Float

Asked by rnb3rd in C Programming Language

Tags: atof, float, string, problem

Hello,

I am having an issue with a function I have written accepting input as a string and converting it to a float usint atof().  When it is run it accepts the string beutifully but does funky things upon conversion.  I have printed out the variables at each step and after conversion my variable dbl_INPUTUSD is equal to "$f" not a number like I need.  Here is the code from my function.  Any help would be appreciated.  I cannot spot the problem...

float fun_Input() // Queries User to Input Amount of USD to Convert to Foreign Currency

{
      
      // Local Variable Declaration and Initialization
      char chr_USERINPUT[80] = {'\0'};
      double dbl_INPUTUSD = 0.0; // US Dollar Input Variable
      
      // Query User for Input and Validate
      while (dbl_INPUTUSD <= 0.0)
      {
            // Query User and Accept Input
            fflush(stdin);
            printf("Please Enter and Amount of US Dollars to Convert: ");
            scanf("%s", chr_USERINPUT); // Input String
            
            printf("\n\n");
            printf("%s", chr_USERINPUT);  // Displays String Input
            
            // Convert String Input to Float
            dbl_INPUTUSD = atof(chr_USERINPUT);  // PROBLEM AREA
            
            printf("\n\n");
            printf("$f", dbl_INPUTUSD);  // Displays Converted Variable
            
            // Validate Input
            if (dbl_INPUTUSD <= 0.0)
                  printf("\n\nYour Input is Completely Invalid!\n\n");
      }
      
      return (dbl_INPUTUSD);            
}

Output is as follows for this function before the return.

Please Enter and Amount of US Dollars to Convert: 3


3                                  <- Input from String Displayed

$f                                 <- PROBLEM


- RIch B
Start Free Trial
 
Keywords: atof() Problem Converting String into …
 
Loading Advertisement...
 
[+][-]08.04.2006 at 01:05PM PDT, ID: 17252774

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.04.2006 at 01:05PM PDT, ID: 17252776

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.04.2006 at 01:08PM PDT, ID: 17252798

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.04.2006 at 01:14PM PDT, ID: 17252837

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.04.2006 at 01:39PM PDT, ID: 17253002

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.04.2006 at 01:44PM PDT, ID: 17253042

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.04.2006 at 01:50PM PDT, ID: 17253087

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.04.2006 at 02:36PM PDT, ID: 17253323

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.04.2006 at 02:49PM PDT, ID: 17253389

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.04.2006 at 04:00PM PDT, ID: 17253655

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: atof, float, string, problem
Sign Up Now!
Solution Provided By: Kdo
Participating Experts: 6
Solution Grade: A
 
 
[+][-]08.05.2006 at 12:32AM PDT, ID: 17255019

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.24.2006 at 06:09AM PDT, ID: 17380937

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.22.2006 at 02:22PM PDT, ID: 17580849

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.27.2006 at 11:22AM PDT, ID: 17612652

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32