LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Program Won't Display Output

Is there a setting I need to enable in CVI to see the output generated by this simple program?
The debug window opens for user input, but disappears after data is input. No errors anywhere.
------------------------------------------------------
#include
int radius, area;
int main(void)
{
printf( "Enter radius (i.e. 10): ");
scanf( "%d", &radius );
area = (int) (3.14159 * radius * radius);
printf( "\n\nArea = %d\n", area );
return 0;
}
------------------------------------------------------
0 Kudos
Message 1 of 7
(3,870 Views)
CVI closes the stdio window as soon as the program exits. Just put a getchar() or something in to give you time to read the output:

#include
int radius, area;
int main(void)
{
printf( "Enter radius (i.e. 10): ");
scanf( "%d", &radius );
area = (int) (3.14159 * radius * radius);
printf( "\n\nArea = %d\n", area );
getchar();
return 0;
}

--
Martin
--
Martin
Certified CVI Developer
Message 2 of 7
(3,870 Views)
Also, if you're using version 7.0 of CVI, there is an option under Options>>Environment called "Copy Standard I/O to Debug Output Window". If you check this option, the CVI run-time will echo your prtinf output to the Debug Window, which does stay around after your program terminates.

Luis
NI
0 Kudos
Message 3 of 7
(3,870 Views)
Thanks for the information and the quick response.
Since I'm using 6.0 I will have to use your solution.
I'm surprised that a product that mature would have to have a work-around for something so obvious. Other compilers don't have a problem displaying the answer.
I want to use NI's compiler since it's friendlier than MS's.
0 Kudos
Message 4 of 7
(3,870 Views)
It's a fair point, and eventually we did "fix" it, but not until 7.0.

The reason why the problem exists in the first place is that the standard I/O window, which receives the output (or the console window), is part of the process of the debuggee, not the debugger (CVI). When the debuggee's process terminates, the window has to be destroyed. This was only an issue in versions 5.5 and 6.0, since prior to that CVI used to debug user programs in-process, in which case we could keep the window around as long as CVI was up.

Eventually we got enough feedback that this was a problem for us to do something about it. Sorry that it took so long 🙂

Luis
0 Kudos
Message 5 of 7
(3,870 Views)
Thanks for the explanation.

Now if fighting another problem, it has to do with
"stdprn", which MS C and NI C doesn't understand as an ANSI-defined value. Sam's Teach Yourself C uses it in one of it's programs and explains that it won't work, but doesn't explain what to substitute in the code to replace it.
Any suggestions or has my question limit been exceeded?
0 Kudos
Message 6 of 7
(3,870 Views)
I expect that stdprn is supposed to represent the parallel port of the PC, which is the traditional location for a printer. This is one of those assumptions that no longer makes sense in the world of Windows. While it might still be possible to print some text, in some cases, by writing directly to the printer, that is not how you should print in a multitasking OS. Printing should be done through the Print Manager which controls the access to the various printer queues by the various windows applications.

If all you want to do is to print some text from CVI, just use the PrintTextBuffer function.

Luis
0 Kudos
Message 7 of 7
(3,870 Views)