🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #299

Re: newbie in turbo c++ 3.0

#299
From: osmium
Date: Sat, 19 Jan 2002 22:37
49 lines
2436 bytes
El writes:

> i'm using turbo c++ 3.0 for writing a very simple program, criteria as
> below:
>
> open a text file which formated as
> first 7 char is ID Number, Next 20 char is Name, Next 3 is marks 1, Next 3
> is marks 2.
> e.g    1002030ANDYLEUNG          100 95
>
> Now I want to open and read the file by using ifstream & ofstream, then
read
> the line
> which specify the length and put it into a defined structure like
>
> struct
> {
> char *id, *name
> int mark1, mark2
> }studrec
>
> however, i didn't know how to read the line with specific length of char
and
> how to loop it until end of file.

Here is a rough cut at it.

struct S
   {
    char id[8];   // pointers are pointless!  You *know* the size.
    char name[21];
    int mark1;
    int mark2;
    };
S s[100];  // space for 100 records
// Assume  a text file named in exists and is open.

int i = 0;
while(in)  // cast will return false at EOF
   {
    in.get(s[i].id, 7);
    in.get(s[i].name, 20);
    in >> s[i].mark1 >> s[i].mark2;
    in.get();  // discard '\n'  vulnerable to trailing blanks.
    i++;
   };

One hopes that that forms a base. After debuggging, of course.  No error
checking.
Technical Details
Message-ID: <rym28.24537$yC.3013265@typhoon.mn.mediaone.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!nntp.cs.ubc.ca!cyclone.rdc-detw.rr.com!news.mw.mediaone.net!typhoon.mn.mediaone.net.POSTED!not-for-mail
References: <a2c5ds$9nj1@imsp212.netvigator.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f8d38,28dabf9af7da2c85
X-Google-Attributes: gidf8d38,public
X-Google-Thread: 109fba,28dabf9af7da2c85
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,28dabf9af7da2c85
X-Google-Attributes: gid114592,public
X-Google-ArrivalTime: 2002-01-19 14:38:52 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!nntp.cs.ubc.ca!cyclone.rdc-detw.rr.com!news.mw.mediaone.net!typhoon.mn.mediaone.net.POSTED!not-for-mail
From: "osmium" <r124c4u2@mediaone.net>
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++
References: <a2c5ds$9nj1@imsp212.netvigator.com>
Subject: Re: newbie in turbo c++ 3.0
Lines: 53
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
Message-ID: <rym28.24537$yC.3013265@typhoon.mn.mediaone.net>
Date: Sat, 19 Jan 2002 22:37:11 GMT
NNTP-Posting-Host: 66.41.136.154
X-Complaints-To: abuse@mediaone.net
X-Trace: typhoon.mn.mediaone.net 1011479831 66.41.136.154 (Sat, 19 Jan 2002 16:37:11 CST)
NNTP-Posting-Date: Sat, 19 Jan 2002 16:37:11 CST