Debug Assertion Error on a sprintf call

This is a discussion on Debug Assertion Error on a sprintf call within the C++ Programming forums, part of the General Programming Boards category; Any idea what might be causing said "Debug Assertion Error" This function will convert the incoming number arguments to string, ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    93

    Debug Assertion Error on a sprintf call

    Any idea what might be causing said "Debug Assertion Error"

    This function will convert the incoming number arguments to string, format them and then store them in "data".

    Code:
    IOLineEdit& IOLineEdit::operator=(double number){
    	char theFormat [20]="%";
        strcat (theFormat, format);
        strcat (theFormat, "lf");
    	sprintf((char*)data,theFormat,number);
    	return *this;
    }
    format is a public member which holds the format of any number
    for instance it will hold .2

    data is a void* from my parent class

    I get the "Debug Asserion Error" on the sprintf line. In the dialogue box the expression says "(STRING!=NULL)".

    Appreciate any help.
    Last edited by INFERNO2K; 11-25-2005 at 07:43 PM.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Is 'data' initialized to any space, or is it NULL?

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    93
    Im guessing I need to allocate space for 'data' within that function?

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Well, you need to allocate space for it "somewhere" at least.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple types in lists, vectors or arrays.
    By megatron09 in forum C++ Programming
    Replies: 20
    Last Post: 08-31-2006, 01:54 PM
  2. Error C2664 - Trying to call an external Dll
    By jamez05 in forum C++ Programming
    Replies: 3
    Last Post: 08-08-2006, 06:07 AM
  3. C system call and library call
    By Coconut in forum C Programming
    Replies: 6
    Last Post: 08-22-2002, 11:20 AM
  4. Assembly example
    By Lynux-Penguin in forum C Programming
    Replies: 6
    Last Post: 04-24-2002, 07:45 PM
  5. Pls help me to do this project in C I need source code
    By sureshmenon74 in forum C Programming
    Replies: 4
    Last Post: 10-04-2001, 06:57 AM

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