B
BGP
I am working on a WIN32 API app using devc++4992 that will accept Dow
Jones/NASDAQ/etc. stock prices as input, parse them, and do things with
it. The user can just cut and paste back prices into a window and hit
a button to process it.
The information thus enters the program as a char array. Prices can be
between $1 and $100, including cents. So we can have prices such as
3.01, 1.56, 11.57, etc. The char array is an alphanumeric string, so
everything that isn't x.xx or xx.xx has to be parsed out.
Once a number gets parsed out, it gets stored in an array for later
use. Eventually, we will display the numbers later, and they must be
in the same two decimal places format.
I am having a terrible time getting the actual API to work. When it
reads data it can get stuck in the loop forever, seemingly never
hitting a NULL. I stripped it down and wrote this small console app to
try to figure out where it is going wrong. Surprise, this app seems to
work without being stuck in a loop.
There is one problem here I can't seem to fix. The buffer should
display the number to two decimal places, but its not doing so. I've
been trying to figure this out for six hours or so and I thought I'd
ask here. When this program is run, the current buffer should display
to two decimal places... Thanks in advance.
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <tchar.h>
using namespace std;
int main(int argc, char *argv[])
{
char rawtxt[] = "parse this 3.50now 4.00 5.67", outtxt[] = "",
temptxt[] = "", buffer[] ="";
int i = 0;
float USERX[5000];
const char delimiters[] = "
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-+=_,!?"; // parse
tchar string by splitting when these chars are found.
char* token;
token = strtok (rawtxt, delimiters); // cut first back price out
of rawtxt
cout << "This program should parse a string into numbers with
decimals." << endl << endl;
cout << "string to parse: " << rawtxt << endl << endl;
while (token != NULL)
{
cout << "current token: " << token << endl;
USERX = atof(token);
_sntprintf(buffer, sizeof(buffer) / sizeof(buffer[0]),
("%4.2f"), USERX);
token = strtok (NULL, delimiters);
cout << "USERX[" << i << "]: " << USERX << endl;
i++;
cout << "current buffer: " << buffer << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Jones/NASDAQ/etc. stock prices as input, parse them, and do things with
it. The user can just cut and paste back prices into a window and hit
a button to process it.
The information thus enters the program as a char array. Prices can be
between $1 and $100, including cents. So we can have prices such as
3.01, 1.56, 11.57, etc. The char array is an alphanumeric string, so
everything that isn't x.xx or xx.xx has to be parsed out.
Once a number gets parsed out, it gets stored in an array for later
use. Eventually, we will display the numbers later, and they must be
in the same two decimal places format.
I am having a terrible time getting the actual API to work. When it
reads data it can get stuck in the loop forever, seemingly never
hitting a NULL. I stripped it down and wrote this small console app to
try to figure out where it is going wrong. Surprise, this app seems to
work without being stuck in a loop.
There is one problem here I can't seem to fix. The buffer should
display the number to two decimal places, but its not doing so. I've
been trying to figure this out for six hours or so and I thought I'd
ask here. When this program is run, the current buffer should display
to two decimal places... Thanks in advance.
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <tchar.h>
using namespace std;
int main(int argc, char *argv[])
{
char rawtxt[] = "parse this 3.50now 4.00 5.67", outtxt[] = "",
temptxt[] = "", buffer[] ="";
int i = 0;
float USERX[5000];
const char delimiters[] = "
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-+=_,!?"; // parse
tchar string by splitting when these chars are found.
char* token;
token = strtok (rawtxt, delimiters); // cut first back price out
of rawtxt
cout << "This program should parse a string into numbers with
decimals." << endl << endl;
cout << "string to parse: " << rawtxt << endl << endl;
while (token != NULL)
{
cout << "current token: " << token << endl;
USERX = atof(token);
_sntprintf(buffer, sizeof(buffer) / sizeof(buffer[0]),
("%4.2f"), USERX);
token = strtok (NULL, delimiters);
cout << "USERX[" << i << "]: " << USERX << endl;
i++;
cout << "current buffer: " << buffer << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}