Solved

Reading text into an array from a file

Posted on 2000-03-28
1
179 Views
Last Modified: 2010-04-02
Hello!

I have a text file of approx 40,000 characters long and want to read it in character by character into an array...process it and then output it to a file. How do you read in for example 500 characters at a time...process them....then output the text to a new file. Then take the next 500 characters of the text and process that...etc.!
0
Comment
Question by:colleen_dana
1 Comment
 
LVL 22

Accepted Solution

by:
nietod earned 80 total points
ID: 2665600
fstream InFil("C:\\SOURCE.TXT",ios_base::in);
fstream OutFil("C:\\DESTINATION.TXT",ios_base::out);

const int BufSiz = 500;
char Buffer[BufSiz];

while(true)
{
   int Len = InFil.readsome(Buffer,BufSiz);
   // process the data in Buffer, not that on the last read the data will only
   // be Len long, not BufSiz long.  So always use Len as the
   // length of the data.
   OutFil.write(buffer,Len);
   if (Len != BufSiz)
      break;
}


let me know if you have any questuions.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question