data type of passed argument

This is a discussion on data type of passed argument within the C Programming forums, part of the General Programming Boards category; Hello, I want to pass the name of double variables as arguments to a function. I tried to do it ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    2

    data type of passed argument

    Hello, I want to pass the name of double variables as arguments to a function. I tried to do it by passing them as string arrays. They passed OK, but the function did not act upon the original double variables as I had intended.
    Can someone please help ? - Can this be done in C ?
    Thanks kindly.

    example of passing the name of a double to the function in the form of a string array:
    Code:
    validChecker("sampleDoubleNameInStringFormat");
    This is the function. How do I get scanf to recognise the string argument as a real double variable ? At the moment it is not.
    Code:
    int validChecker(char argumentRepresentingADoubleVariable[]) {
          scanf("%lf", &argumentRepresentingADoubleVariable);
     return 0;   
    }

  2. #2
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    455
    you can't do type mismatch like that. you can't read double into a string. If you want to scan into a variable like that you have to pass in as pointer.
    Code:
    void validChecker( double *var)
    {
         scanf("%lf",var); 
    }
    
    ...
    int main()
    {
       double x; 
       validChecker(&x); 
        return 0; 
    }
    Last edited by nimitzhunter; 01-07-2011 at 11:13 PM.
    "All that we see or seem
    Is but a dream within a dream." - Poe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling Libraries in C
    By TheOriginalGame in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 11:19 AM
  2. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21