D
ddk1965
Hello,
I am reading from a comma separated file cvs some date.
The data look like this:
"John Poe",3.4,100
"Alice",7,250
I use this routine to find the 3 fields:
void parsecsv (char *pfld[], long *n, char *pstr) {
/* extracts fields from a string containing a csv record */
*n=1;
pfld[0]=pstr;
while(*pstr) {
if(*pstr == ',') {
*pstr=0;
pfld[*n]=pstr+1;
++(*n);
}
++pstr;
}
}
in my main.c:
static char dlnbuf[MAXSTR], *pfld[20];
static long nfld;
parsecsv(pfld,&nfld,dlnbuf); /* read the fields into separated
parts into pfld */
for(k=0; pfld[0][k]; k++) if(pfld[0][k]=='"') pfld[0][k]=' '; /
* to remove the " from the name */
sscanf(pfld[0], "%s", &name);
Now my problem:
I get only the first part of the name till it reaches a blank
so I get
John
Alice
and not
John Poe
Alice
What I am doing wrong?
Tx,
Danny
I am reading from a comma separated file cvs some date.
The data look like this:
"John Poe",3.4,100
"Alice",7,250
I use this routine to find the 3 fields:
void parsecsv (char *pfld[], long *n, char *pstr) {
/* extracts fields from a string containing a csv record */
*n=1;
pfld[0]=pstr;
while(*pstr) {
if(*pstr == ',') {
*pstr=0;
pfld[*n]=pstr+1;
++(*n);
}
++pstr;
}
}
in my main.c:
static char dlnbuf[MAXSTR], *pfld[20];
static long nfld;
parsecsv(pfld,&nfld,dlnbuf); /* read the fields into separated
parts into pfld */
for(k=0; pfld[0][k]; k++) if(pfld[0][k]=='"') pfld[0][k]=' '; /
* to remove the " from the name */
sscanf(pfld[0], "%s", &name);
Now my problem:
I get only the first part of the name till it reaches a blank
so I get
John
Alice
and not
John Poe
Alice
What I am doing wrong?
Tx,
Danny