LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

compiled c output places cursor at end of line

When I use the following line in LabWindows/CVI:

printf("Enter a number:_______\b\b\b\b\b\b\b");

I expect the cursor to be immediately after the ":", but it ends up after the last _. I've got confirmation that another C compiler produces the result I'm looking for, but why not CVI? Any advice?
0 Kudos
Message 1 of 12
(4,390 Views)
I tried using that, and it seemed to work fine. What version of LW/CVI are you using? Maybe it was an issue that they resolved, bescause I am using 7.0. Otherwise, you could probably just get rid of the underscores and that would work, if you're not too attached.

Derek

0 Kudos
Message 2 of 12
(4,390 Views)
Derek,

Version 7.0.0 build 393.

Code:
-----------------------------------------------
#include


int main(void)
{
float salary=0.0f;
char sBuff[24];

printf("Enter your desired monthly salary:");
printf(" $_______\b\b\b\b\b\b\b");
fflush(stdin);
gets(sBuff);
sscanf(sBuff,"%f",&salary);

printf("\n\t%.2f a month is $%.2f a year.", salary, salary*12);

printf("\rGee!\n");
printf("\nPress Enter key to Exit.");
fflush(stdin);
getchar();
return 0;
}

Results:
-------------------------------------
Enter your desired monthly salary: $_______2000
Gee!0.00 a month is $24000.00 a year.
Press Enter key to Exit.
0 Kudos
Message 3 of 12
(4,390 Views)
I'm not sure what the problem is. It works fine for me.
I get this:
Enter your desired monthly salary: $2000___
Gee!0.00 a month is $24000.00 a year.
Press Enter key to Exit."

Sorry I can't be of any help.

Derek

0 Kudos
Message 4 of 12
(4,390 Views)
Is it something in the build options? I've tried changing to stdcall and Borland C/C++, but no dice.

Jason
0 Kudos
Message 5 of 12
(4,390 Views)
I do not believe it would have anything to do with the build options. I've been trying everything trying to reconstruct your problem, but to no avail. I'll keep trying, and if I figure somehting out I'll let you know.

Derek
0 Kudos
Message 6 of 12
(4,390 Views)
I've also gotten the same results on a different machine with 7.0.0 build 393 installed. Bloodshed DevCPP compiles it just fine.
0 Kudos
Message 7 of 12
(4,390 Views)
Hi swoboda,

Unfortunately, I cannot recreate the issue you are seeing. Mine runs just the same as the others. The cursor is positioned on the first underscore. What happens if you build a new project and insert the code into a new source (.c) file? Does the problem persist?

Jeremy L.
National Instruments
Jeremy L.
National Instruments
0 Kudos
Message 8 of 12
(4,390 Views)
Jeremy,

I tried this and the problem persists. I set the build options to release executable. Compile the salarynew.c file, build a release executable and run the salarynew.exe release executable. My prompt is at the end of the first line. Additionally, the second line doesn't seem to tab correctly.

If it's any help, I am building this on a fresh installation of CVI70 at the Houston training center. If you can get to a machine with the current training ghost image on it you should have the same setup I do.

Results and project files are attached.

Thanks,

Jason Swoboda
Omnia Technology
Houston, TX
Download All
0 Kudos
Message 9 of 12
(4,390 Views)
Hi Jason,

I was able to reproduce the error here. The problem lies in which I/O window you are using. If you run your application from CVI, it automatically uses the Windows Standard I/O Window, which is the black background window. When you created your executable, you didn't set it to be a console application, and so it used the CVI native I/O window (white background), which is known to have a few issues. So, when I changed your app to use the Windows Standard I/O Window, the problem went away. To use this window when you build your application, go to Build >> Target Settings. Make sure "Create Console Application" has a check mark next to it. The next time you build and run, it will know now to use the Windows Standard I/O, and you will
see the results you wanted.

Jeremy L.
National Instruments
Jeremy L.
National Instruments
0 Kudos
Message 10 of 12
(4,390 Views)