PE> P.S. Could you send me an updated copy of your database of stock purchases
PE> done by me? Thanks. BTW, I now have my own database-format for the thing,
PE> previously I have only entered them as an English description of what I'd
PE> done.
Here is the conversion program if you are interested...
/*********************************************************************/
/* */
/* This Program Written by Paul Edwards, 3:711/934{at}fidonet. */
/* Released to the Public Domain */
/* */
/*********************************************************************/
#include
#include
typedef struct {
char buysell[4];
char asxcode[10];
char saleDate[20];
char quantity[20];
char sd[20];
char brokerage[20];
char filler[10];
char who[5];
char basePrice[20];
char totalPrice[20];
char salePrice[20];
} STOCKREC;
static STOCKREC stockrec;
static char buf[200];
static char tokens[50][50];
static void tokenise(void);
static void stripquote(char *p);
static void allocate(void);
int main(void)
{
while (fgets(buf, sizeof buf, stdin) != NULL)
{
tokenise();
allocate();
fprintf(stdout,
"%s %s %s %s %s %s %s %s %s %s\n",
stockrec.saleDate,
stockrec.buysell,
stockrec.asxcode,
stockrec.quantity,
stockrec.salePrice,
stockrec.basePrice,
stockrec.brokerage,
stockrec.sd,
"0",
stockrec.totalPrice);
}
return (0);
}
static void tokenise(void)
{
char *p;
char *q;
int x = 0;
q = buf;
while ((p = strchr(q, ',')) != NULL)
{
*p = '\0';
stripquote(q);
strcpy(tokens[x], q);
q = p + 1;
x++;
}
p = strchr(q, '\n');
if (p != NULL)
{
*p = '\0';
}
stripquote(q);
strcpy(tokens[x], q);
}
static void stripquote(char *p)
{
size_t x;
if (*p == '"')
{
memmove(p, p + 1, strlen(p));
}
if (*p == '-')
{
memmove(p, p + 1, strlen(p));
}
x = strlen(p);
if (x > 0)
{
x--;
if (p[x] == '"')
{
p[x] = '\0';
}
}
return;
}
static void allocate(void)
{
char *p;
int y, m, d;
strcpy(stockrec.buysell, tokens[0]);
if (strcmp(stockrec.buysell, "I") == 0)
{
strcpy(stockrec.buysell, "B");
}
else if (strcmp(stockrec.buysell, "D") == 0)
{
strcpy(stockrec.buysell, "S");
}
strcpy(stockrec.asxcode, tokens[1]);
strcpy(stockrec.saleDate, tokens[2]);
sscanf(stockrec.saleDate, "%d/%d/%d", &d, &m, &y);
sprintf(stockrec.saleDate, "%.4d-%.2d-%.2d", 1900 + y, m, d);
strcpy(stockrec.quantity, tokens[3]);
p = strstr(stockrec.quantity, ".00");
if (p != NULL)
{
if (strcmp(p, ".00") == 0)
{
*p = '\0';
}
}
strcpy(stockrec.sd, tokens[4]);
if (strcmp(stockrec.sd, "") == 0)
{
strcpy(stockrec.sd, "0");
}
strcpy(stockrec.brokerage, tokens[5]);
if (strcmp(stockrec.brokerage, "") == 0)
{
strcpy(stockrec.brokerage, "0");
}
strcpy(stockrec.filler, tokens[6]);
strcpy(stockrec.who, tokens[7]);
strcpy(stockrec.basePrice, tokens[8]);
strcpy(stockrec.totalPrice, tokens[9]);
strcpy(stockrec.salePrice, tokens[10]);
return;
}
@EOT:
---
* Origin: X (3:711/934.9)
|