From: "Tim 'Zastai' Van Holder" Newsgroups: comp.os.msdos.djgpp References: Subject: Re: Importing text into a char array Lines: 58 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: Date: Sat, 26 Aug 2000 17:18:29 GMT NNTP-Posting-Host: 213.224.93.160 X-Trace: afrodite.telenet-ops.be 967310309 213.224.93.160 (Sat, 26 Aug 2000 19:18:29 MET DST) NNTP-Posting-Date: Sat, 26 Aug 2000 19:18:29 MET DST Organization: Pandora - Met vlotte tred op Internet To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "David Roon" wrote in message news:Pine DOT GHP DOT 4 DOT 21 DOT 0008251135110 DOT 14459-100000 AT falcon DOT csrv DOT uidaho DOT edu... > > > ---------- Forwarded message ---------- > Hullo, folks... > > I'm writing a program to analyze genetic data- I'd like to be able to > import numerical data from a text file and assign it to elements within a > char array. Is there some way to use the getline() function for this, or > do I need some other approach? > Depends on how much you know of the file format; if it's well-defined (for example, each line starts with a word with no embedded whitespace, followed by a set of numbers), you could just use the >> operator (C++) or fscanf (C). If the format of the file is less clear-cut, a more robust system would be needed; this would probably involve reading the file line by line (or char by char) and then trying to parse the data in it yourself. However, from what you describe, it's likely the input file will be well- formatted, so the following (C++) programlet will likely do what you want: #include #include using namespace std; int main(void) { // Open the input file for reading ifstream fin("genetic.dat", ios::in | ios::text); // Prepare an array to hold the data; I use a deque here for // the convenient push_back; of course a vector or valarray // may be more appropriate. deque data; double value; fin >> value; // get first value while (!fin.eof ()) { data.push_back(value); fin >> value; } // Now process the data Analyze(data); // And we're done return 0; } If C is required, I'm sure some other kind soul will be willing to post the C equivalent of this. -- Hi, I'm a signature virus. plz set me as your signature and help me spread :)