Problem with double conversion to char*

This is a discussion on Problem with double conversion to char* within the C Programming forums, part of the General Programming Boards category; Hi I am working with Opencv and it has a function cvGetCaptureProperty which returns a double. There is one case ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    2

    Problem with double conversion to char*

    Hi I am working with Opencv and it has a function cvGetCaptureProperty which returns a double. There is one case where I need to convert the double into char* and the sample code is provided below. The problem is that, the conversion does not return any value.


    double f = cvGetCaptureProperty(capture, CV_CAP_PROP_FOURCC);
    char* fourcc = (char*) (&f);
    cout<<"\nf_double: "<<f<<"\nfourcc: "<<fourcc<<"\n";

    Output: f has a value but fourcc has no value.
    Any help will be appreciated. Thanks.

    Regards
    Luhfluh

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,185
    Use sprintf. You should probably also read up on strings and pointers to understand why what you do doesn't work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    2
    Quote Originally Posted by Elysia View Post
    Use sprintf. You should probably also read up on strings and pointers to understand why what you do doesn't work.
    Hi, thanks for the heads up. Figured it out after some strings and pointer notes, much appreciated

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    That statement will print the location of f; for its contents use *fourcc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  3. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 05:54 PM
  4. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 08:44 PM
  5. getline problem
    By scottmanc in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2003, 09:27 PM

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