11-28-2005 11:14 AM
11-28-2005 11:26 AM
11-28-2005 11:44 AM
11-28-2005 02:31 PM
11-28-2005 02:39 PM - edited 11-28-2005 02:39 PM
OK, to read the number from the buffer you may use
sscanf (readBuffer + 1, "%d", &number); // This fills an integer variable with your data, skipping initial character
sscanf (readBuffer + 1, "%f", &number); // This read back in a double variable
To create a string with your data to show in the text box, simply use the following:
sprintf (buffer, "%d", number); // Writes the first number
sprintf (buffer, "%s\n%d", buffer, number); // Writes the 2nd (3rd, 4th...) number to the string
In the above statements "%d" can be substituted with "%f" for floating points numbers.
As an alternative, you may want to look of the examples in the online help, looking into the "Formatting and I/O library" chapter of the user guide: these will drive you in the use of Scan and Fmt native functions.
sscanf and sprintf are very big and complex commands that can be customized to fulfill your needs: their explanation goes beyond the scpe of this forum and I strongly reccommend that you study them on a c-language manual in order to use them at the best.
Message Edited by Roberto Bozzolo on 11-28-2005 09:44 PM
11-29-2005 05:12 AM
You might find it easier to use:
number = atoi (readBuffer + 1);
Noting that number is an integer, which you can copy to a float/double type variable later, if you prefer.
JR
11-29-2005 07:29 PM
11-30-2005 05:53 AM
As Roberto suggested, you will need the sprintf() function. Something like:
char string [32];
float number = 1234;sprintf (string, "%f", number); // "%g" is an alternative if there is never a fractional part
There is a wide variety of formatting options, such as: number of decimal places; forced sign inclusion; engineering/scientific notation etc. You may need to read up on all the options for the function in a good ANCI C text book.
JR
11-30-2005 10:33 AM
11-30-2005 10:47 AM