🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Manipulating Input

#408
From: BERN
Date: Sat, 10 Oct 1998 00:00
71 lines
2264 bytes

Mariana wrote:

> Hi,
>
> I am trying to find a way of manipulating input from a txt file.
> The following is a portion of the code,
>
> void DisplayPointsTable()
> {
> char FileName[13];
> char ch;
> clrscr();
> cout << "\nPlease type name of file to load... ";
> cin >> FileName;
> ifstream FileIn;
> FileIn.open(FileName);
>
> clrscr();
> if(!FileIn)
> {
>         cerr << "\nThis file could not be found." << endl;
>    exit(1);
> }
>
> cout << endl;
>
> while (!FileIn.eof())
> {
>     FileIn.get(ch);
>     cout << ch;
> }
> FileIn.close();
> }
>
> -----------------------------------
>
> This reads in a txt file from disk and outputs the contents to the screen
> fine, what I would like to do is read the input into an array for example
> and then output the data to screen in different positions.
> For example.
> The txt file on disk looks like this.
>
> 3  4  John
> 4  5  Bill
> 4  6  House
>
> I would like to do this
>
> John    3       4
> Bill    4       5
> House   4       6
>
> As I said I can read the data in from a file and display it to screen in
> its original format, but for the life of me I can't work out how to do
> the above. Any thoughts would be appreciated.
>
> Cheers

#include<fstream.h>int max = 20 ;  // max charactors to get
char word_in_line[3][max]={0};  2 dim. array to split up the 3 "words"
input.open("textfile.txt") ;
input.getline(word_in_line[0] ,'32') ;  //stops at the first white space   32
= spacebar
input.getline(word_in_line[1] ,'32')
input.getline(word_in_line[2] ,'32')

input.close( ) ;

//you can now output them any why you like
Technical Details
Message-ID: <361F67E1.318A876D@huntel.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <MPG.1089a043d48ce4df989680@news.ozemail.com.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f8d38,77461b0e4c74496d
X-Google-Attributes: gidf8d38,public
X-Google-Thread: 114592,77461b0e4c74496d
X-Google-Attributes: gid114592,public
From: BERN <boyer@huntel.net>
Subject: Re: Manipulating Input
Date: 1998/10/10
Message-ID: <361F67E1.318A876D@huntel.net>
X-Deja-AN: 399665853
Content-Transfer-Encoding: 7bit
References: <MPG.1089a043d48ce4df989680@news.ozemail.com.au>
Content-Type: text/plain; charset=us-ascii
Organization: netINS, Inc.
Mime-Version: 1.0
Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language