Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3577
  • Last Modified:

How to compile a call to _stprintf_s from MSVC

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
#else
#define _ttof atof
#endif

Line is :      _stprintf_s(sret, BUFSIZE, TEXT("%f"), 25569 + _ttof(sret) / (3600.0 * 24.0));
Error is :     error C2065: '_wtof' : undeclared identifier
0
plq
Asked:
plq
1 Solution
 
Jase-CoderCommented:
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)
0
 
jkrCommented:
Try providing a simple adapter functions like

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

      va_list      args;

      va_start (args, format);

      ret = _vstprintf( buffer, format, args);

        va_end(args);

        return ret;
}

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

    wcstombs(p,string,len);

    ret = atof(p);

    free(p);

    return ret;
}
#endif
0
 
plqAuthor Commented:
You rock jkr
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now