Mail Archives: djgpp/1997/11/30/16:03:42
This is a multi-part message in MIME format.
--------------F1B0BC94AE708FE69D60FC7E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Dean wrote:
>
> Here's an example of a file I want my program to read:
>
> "B02304Y8412","01:37","26-11-97"
> "B02321X8412","01:37","26-11-97"
>
> I tried the following code:
>
> input = fopen( filename, "rt" );
>
> while( fscanf( input, "\"%s\",\"%s\",\"%s\"\n", code, time, date ) )
> {
> //do stuff to code, time and date
> }
>
> but the loop is never entered.
>
> I also tried the following C++:
>
> ifstream input;
> input.open ( filename, ios::nocreate );
>
> while( !input.eof() )
> {
> input << "\"" << code << "\",\"" << time << "\",\"" << date << "\"\n";
>
> //do stuff to code, time and date
> }
>
> but the same thing happened. I also tried removing all the \" but
> still nothing.
How about this:
struct record {
char skip1; /* opening quote */
char id[11];
char skip2[3]; /* quote comma quote */
char time[5];
char skip3[3]; /* quote comma quote */
char date[8];
char skip4; /* closing quote */
};
union {
struct record data;
char line[32+3]; /* length of record + CR/LF + NULL */
} input;
/* open file */
while (fgets(input.line, sizeof(input.line), fp) != NULL) {
/* use input.data.id, input.data.time and input.data.date here */
}
--
Weiqi Gao
weiqigao AT a DOT crl DOT com
--------------F1B0BC94AE708FE69D60FC7E
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Weiqi Gao
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: Weiqi Gao
n: Gao;Weiqi
org: Spectrum Healthcare Services
adr: 12647 Olive Blvd.;;;St. Louis;MO;63141;U. S. A.
email;internet: weiqigao AT a DOT crl DOT com
title: Sr. Programmer Analyst
tel;work: (314)-919-9816
tel;fax: (314)-919-8913
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
version: 2.1
end: vcard
--------------F1B0BC94AE708FE69D60FC7E--
- Raw text -