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
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <grx20.h>
- int i,j;
- float v[100];
- char *buffer[80];
- main()
- {
- for (i=0 ; i<80 ; i++)
- {
- v[i]=2*i;
- printf("%d %f\n", i, v[i]);
- gcvt(v[i], 3, buffer);
- memset(buffer; );
- }
- printf("%c", buffer);
- system("PAUSE");
- graphics();
- }
- graphics()
- {
- GrSetMode(GR_default_graphics);
- GrClearScreen(15);
- while (j<80)
- {
- GrTextXY(30,30,"??????",0,15);
- j++;
- }
- GrKeyRead();
- }