How to compile a call to _stprintf_s from MSVC

Posted on 2007-07-28
Last Modified: 2013-12-14
Hi Folks

Can anyone tell me if theres a C runtime equivalent to _stprintf_s available from MSVC6 ? When I compile my project in MSVC6 it raises

       "error C2065: '_stprintf_s' : undeclared identifier"

It compiles in the .net 2005 compiler ok

Also I have the same problem with _ttof (_wtof)

#ifdef UNICODE
#define _ttof _wtof
#define _ttof atof

Line is :      _stprintf_s(sret, BUFSIZE, TEXT("%f"), 25569 + _ttof(sret) / (3600.0 * 24.0));
Error is :     error C2065: '_wtof' : undeclared identifier
Question by:plq
    LVL 11

    Expert Comment

    Hi you can use _stprintf

    when MS released VS2005 they made secure versions of the standard library functions hence the _s at the end of the function names. _wtof is a function only available in the .VS2005(CRT)
    LVL 86

    Accepted Solution

    Try providing a simple adapter functions like

    #if ( _MSC_VER < 1400) // provide implementations for all compilers
                                           // prior to VC8
    int _stprintf_s(
       size_t sizeOfBuffer,
       const TCHAR *format ,
            int ret;

          va_list      args;

          va_start (args, format);

          ret = _vstprintf( buffer, format, args);


            return ret;

    double _wtof( const wchar_t *string )
        double ret;
        size_t len = wcslen(string) + 1;
        char* p = (char*) malloc(len);


        ret = atof(p);


        return ret;
    LVL 8

    Author Comment

    You rock jkr

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    scoresAverage challenge 8 59
    for loop with Set 4 38
    Using YubiKey with REST API application 2 55
    countX 22 53
    A short article about a problem I had getting the GPS LocationListener working.
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now