Hi,

There're a lot of ways to do this ...

If you know the lenght of all the parts you can use the strncpy (ANSI C) function (or StrNCopy if you are using the Palm SDK. Both functions copy N characters from the source string to the destination. To set the start point of the source string, you can use a pointer to char.

ANSI definition: http://man.he.net/man3/strncpy
Palm SDK: http://www.palmos.com/dev/support/docs/palmos/StringManager.html#1065629


A simple code can help you. It's very rudimentary, but I think it's clear enough ;)

{
char str1[78] = "A1111122222Company Name Address Field Y030200"
char *tmp;
CustomerFF customer;


// We start with the first character. The name of the array refers to the memory position
tmp = str1;
strncpy(customer.Action, tmp, 1);
tmp += 1; // Advance the pointer to the next element
strncpy(customer.CustNo, tmp, 5);
tmp += 5; // Advance the pointer to the next element
// etc ...
}


Another way is to use a character separating the diferent fields and use strstr() to find them or strtok().

To answer the second question, you need to use a floating point data like float or double. The number of decimal places can be truncated in the moment of print it.

Hope this help you,

Fernando Rodr�guez Sela


Chris Hall wrote:

   My C is a bit rusty (my primary experience is Cobol based) .... I was
wondering if anyone can help me out here.  I have a data string that I want
to move into individual fields of a structure...   How can I do this?

   Also, how do I define the field in my structure if I want a numeric
field with 2 decimal places assumed.  I have a discount field that would be
coming from str1 as 0200 (last four characters).  I want this field defined
as numeric with 2 decimals assumed (I know Disc Percent in my structure is
incorrect).


Char str1[78] = "A1111122222Company Name Address Field Y030200"

struct CustomerFF
{
     Char Action[1];
     Char CustNo [5];
     Char CustLoc[5];
     Char CustName[30];
     Char Addr[30];
     Char AuthF[1];
     Char PriceNo[2];
     Char DiscPct[4];  ?????
} CustomerFF;


Thanks so much!
Chris




--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to