473,414 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Printing a float in a grx20.h

Firstly, my compiler is dev-C++, and I'm writing the program in C, using stdio.h, stdlib.h, math.h and grx20.h.

I have a value for velocity defined as a float (v[i]) which changes over time, which in my program has already been calculated for the various different i values. I want to print the value of v[i] for i=0 in the grx20.h window, then the program pauses using the sleep function, and then as i is increased (affecting lots of different variables) I want the velocity value to change. This display will effectively serve as a digital speedometer.

I've looked into a number of options. I can't imagine it would make any difference, but I'm currently using GrTextXY to plot the text.

As far as I can see I need to convert the velocity float to a character string that is memorised for different values of i, but I'm not sure if this is possible.

I have tried using the gcvt function, and think I need to combine it with memset? Can anyone help?

I've devised a simple example to help me try to work this out, by working off this I'll be able to implement the code into my program:

Expand|Select|Wrap|Line Numbers
  1.  #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <grx20.h>
  5.  
  6. int i,j;
  7. float v[100];
  8. char *buffer[80];
  9.  
  10. main()
  11. {
  12. for (i=0 ; i<80 ; i++)
  13. {
  14. v[i]=2*i;
  15. printf("%d %f\n", i, v[i]);
  16. gcvt(v[i], 3, buffer);
  17. memset(buffer; );
  18. }
  19. printf("%c", buffer);
  20. system("PAUSE");
  21. graphics();
  22. }
  23.  
  24. graphics()
  25. {
  26.            GrSetMode(GR_default_graphics);
  27.            GrClearScreen(15);
  28.            while (j<80)
  29.            {
  30.            GrTextXY(30,30,"??????",0,15);
  31.            j++;
  32.            }
  33.  
  34.  
  35.  
  36.            GrKeyRead();
I may be completely wrong here, what I'm really struggling with is how to store all those float values as characters, so that I'm able to print them in the graphics window. Then I need to understand how to print the right float value based on my integer.
Nov 9 '11 #1
1 2435
johny10151981
1,059 1GB
you can use sprintf function to create your required string.
Nov 9 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Patrick De Ridder | last post by:
How can I turn what I want to print 90 degrees using the logic below? Please tell me the code with which to make the modification. Many thanks, Patrick. using System.ComponentModel; using...
10
by: Jeff B. | last post by:
Has anyone come across a decent algorithm for implementing word wrap features in .net printing? I have a small component that uses basic printing techniques (i.e. e.Graphics.DrawString in a...
5
by: Lloyd Dupont | last post by:
I'm trying to print some of my document. The problem is, the rendering of the document is not done through GDI+ at all but through plain old GDI, and I need it like that as I am using Uniscribe to...
4
by: Rob T | last post by:
I have a small VB program that has a printing module...very simple....and works great. However, If I try to print to a generic printer, I get the following error: "The data area passed to a...
5
by: Tom | last post by:
I am converting an old application that was printing directly to a specialized printer device (i.e. a special label printer). It was doing this by opening a file with the file path of 'LPT1:' and...
7
by: DazedAndConfused | last post by:
I have a 8.5 x 11 landscape document with about 1/4 inch of space on the left and right where there is no print. The document displays perfect in print preview, but when I print it, about 1/2 inch...
2
by: gdarian216 | last post by:
the program reads input from a file and then outputs the averages and grade. for some reason it is reading in the same line twice and it doesn't print out the grade. everything else is correct, if...
8
by: Frank Rizzo | last post by:
I am trying to print huge images (much bigger than target paper). I try and use e.PageSettings.HardMarginX and e.PageSettings.HardMarginY in the PrintDocument's PrintPage event to try and...
0
by: Iain Wilson | last post by:
I am pulling my hair out trying to print various objects from a .net web page My apologies for cross posting but I need an answer and my previous post has attracted no interest. ASP.Net 2.0...
7
by: Iain Wilson | last post by:
I am pulling my hair out trying to print various objects from a .net web page My apologies for cross posting but I need an answer and my previous post has attracted no interest. ASP.Net 2.0...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.