From: Weiqi Gao Newsgroups: comp.os.msdos.djgpp Subject: Re: Reading in a file Date: Sun, 30 Nov 1997 14:52:43 -0600 Organization: Spectrum Healthcare Services Lines: 87 Message-ID: <3481D21B.D6EE4D00@a.crl.com> References: <34814e4c DOT 33917112 AT news DOT zip DOT com DOT au> NNTP-Posting-Host: a116010.stl1.as.crl.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F1B0BC94AE708FE69D60FC7E" To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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--