LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

*nprintf functions (snprintf, vsnprintf, ...)

i am searching for snprintf() and vsnprintf() in the stdio.h and can't find them. it seems they are still not supported in CVI 8.5.

is there a plan to have those 2 simple functions soon ? in their complete and correct form, that is returning the length of the data that would have been written if those data were not truncated due to the buffer limit.

thanks in advance.
0 Kudos
Message 1 of 10
(9,355 Views)

This was briefly mentioned on the forums before here:

http://forums.ni.com/ni/board/message?board.id=180&message.id=27474&query.id=154974#M27474

and a few other places if you search for snprinft.

I've been close to downloading a portable library before and now I have... There are a few options out there:

http://www.ijs.si/software/snprintf/

http://www.jhweiss.de/software/snprintf.html

I'm linking to the 2nd one now and will let you know if I run into any problems.

gvan

0 Kudos
Message 2 of 10
(9,347 Views)
thank you. i've already read those posts. i am currently trying to use the first one, and after configuring all the #define it seems to work pretty well for my needs.

but, i do regret those functions are not part of the C runtime provided with CVI, given that there is nothing difficult in implementing them. i know that NI is slowly implementing C99 features into CVI: maybe the next step would be to add all the missing functions of the C runtime...


0 Kudos
Message 3 of 10
(9,343 Views)
Hi gvan,
 
I was able to get http://www.ijs.si/software/snprintf/ working in CVI, but it looks like there is no floating point support!
 
I was wondering if you have been able to get http://www.jhweiss.de/software/snprintf.html to work in CVI?
 
Thanks for any help you can give me!
 
Scott.


Message Edited by Scott Y on 04-04-2008 12:30 PM
0 Kudos
Message 4 of 10
(9,215 Views)
No offical promises, but snprintf and vsnprintf will likely make their way into stdio.h in the next major release of CVI.

Mert A.
National Instruments


Message Edited by Mert A. on 04-04-2008 01:20 PM
0 Kudos
Message 5 of 10
(9,209 Views)

Thanks Mert!

It is good to hear that vsnprintf might be added soon.

I did mange to get the C99 version of the snprintf.c going in CVI without too much trouble this afternoon.

Hope all is well at NI.

Scott Y.

0 Kudos
Message 6 of 10
(9,205 Views)

Hello Scott,

 

your wrote that you got the C99 version of snprintf working with CVI. I tried the same thing!

Can you explain how you did it? Perhaps you have a little example program Smiley Happy?

 

Thanks a lot.

 

Alex

0 Kudos
Message 7 of 10
(8,787 Views)

alternatively, i discovered that the Windows Platform SDK includes a "strsafe.h" header defining a set of StringCb* and StringCch* functions which are good replacements for sprintf, snprintf and the likes. those functions are not straight replacement since argument ordering or return value may differ from their C counterparts, but writing an adapter should not be difficult.

 

it seems this header is not part of the SDK included with CVI, but you may download the latest SDK from microsoft and use it.

by the way, is there a chance we have an updated SDK coming with CVI in a near future ?

 

0 Kudos
Message 8 of 10
(8,765 Views)

That is a much better solution. I wish I had found those SDK functions instead of adding an entire library to all my code.

 

HRESULT StringCchPrintf(      
    LPTSTR pszDest,
    size_t cchDest,
    LPCTSTR pszFormat,
     ...
);

 

int snprintf(char *str, size_t size, const char *format, ...);

 

It should be easy to make those line up with just a very thin header file.

I think that must be the "right" way to do it until CVI is updated to support snprintf() and the like.

 

Scott.

 

0 Kudos
Message 9 of 10
(8,761 Views)

The Beta for CVI 9.0 includes an updated windows SDK (I'm not sure how up to date, but appears faily recent, certainly better then the current WIN2000 RC1 SDK)

 

The 9.0 Beta also has suppport for more C99 extentions including snprintf and vsnprintf.


Greg

 

 

 

 

 

 

0 Kudos
Message 10 of 10
(8,757 Views)