LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Why is CVI 7.0 C compiler NOT ANSI compliant

The following code segment works in an ANSI compliant compiler:

char argbuf[500];
int respSize;
char *pTitle, *msgText;

sprintf (argBuf, "[%*s][%s][%s]", respSize, " ", pTitle, msgText);

At runtime CVI ignores the field width argument (respSize) and then tries to use it as a char * argument.
0 Kudos
Message 1 of 4
(3,387 Views)
The code you attached should work, and it works in my computer. I tried running this in the interactive window:

#include
static char argbuf[500];
static int respSize = 10;
static char *pTitle = "title", *msgText = "message";

sprintf (argbuf, "[%*s][%s][%s]", respSize, " ", pTitle, msgText);

...and at the end, argbuf contains the following value:

"[ ][title][message]"

What happens when you run it? Do you get a runtime error complaining about respSize? What is the exact error message?

By the way, I noticed that the you have a typo in the first argument to sprintf (argBuf vs. argbuf). Is it possible that the error could be referring to this?

Luis
NI
0 Kudos
Message 2 of 4
(3,388 Views)
The problem is that there should be 10 spaces between the first set of brackets; the * in the first conversion specification indicates that respSize is supposed to specify a minimum field width.  See: http://man.he.net/?topic=sprintf&section=all
I'm replying to this old post because I'm about to link to this post in a new one with a similar question.
0 Kudos
Message 3 of 4
(3,200 Views)

On my machine (Win XP Pro SP2) Luis code gives expected results (including the 10 spaces between the first two brackets).

Tested on:

CVI 6.0.0 (105)
CVI 7.1.1 (313)
CVI 8.0.1 (356)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(3,191 Views)