Mail Archives: djgpp/1999/05/16/20:01:43
Message-ID: | <373EE5D9.EF32E9FA@enter.net>
|
Date: | Sun, 16 May 1999 11:35:53 -0400
|
From: | Sean <sproctor AT enter DOT net>
|
X-Mailer: | Mozilla 4.51 [en] (Win98; U)
|
X-Accept-Language: | en
|
MIME-Version: | 1.0
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: String arrays...
|
References: | <LOzMxDAi+sP3EwcQ AT zaynar DOT demon DOT co DOT uk>
|
NNTP-Posting-Host: | 207.16.153.95
|
X-Original-NNTP-Posting-Host: | 207.16.153.95
|
X-Trace: | 16 May 1999 11:35:21 -0400, 207.16.153.95
|
Organization: | Enter.Net
|
Lines: | 34
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Unigni wrote:
>
> I'm making a program which needs to read a mixture of number and words
> from a text file. For words, I'd use:
> char name[10];
> or something like that, to be able to store a word up to 10 characters
> long, and read data from the file into this ("dataFile >> name;"). I
> also use:
> int number;
> to be able to read a number. However, when reading more than one lot of
> data, I could use:
> int number[5];
> but what would I do for 'name', and how would I read data into it from a
> file?
>
> Any help will be greatly appreciated!
Depends what you're using to read. If you're using C++ you could do
something like this. I'm assuming you want to know how to put the names
in arrays, I'm not really sure what you want.
#include <fstream.h>
...
ifstream infile("filename");
char name[5][10];
for(int k = 0; k < 5; k++)
infile >> name[k];
This would read 5 names of up to 9 characters (not 10, you need the null
to end the string) separated by white space from file filename into your
array.
Sean
- Raw text -