Solved

Readinf file and parsing

Posted on 2003-11-29
1
226 Views
Last Modified: 2010-04-02
Hi!
I am trying to read the file below and store into array.
Each number is between 1 – 80 and number of line will be between 1 – 10,000.
Also, is it good idea to use array since this file might contains 10,000 of line?

Ex)
3:  1,  4,  5, 10, 14, 15, 16, 19, 22, 25, 26, 37, 38, 42, 50, 56, 62, 70, 74, 80
1:  6, 12, 27, 28, 29, 30, 33, 36, 37, 39, 41, 43, 46, 49, 56, 57, 59, 62, 73, 80
….
….
….
0
Comment
Question by:dkim18
1 Comment
 
LVL 3

Accepted Solution

by:
gkatz earned 100 total points
ID: 9843680
depending on the file size it may not be a good idea to use a regular array.  Arrays are allocated in the stack and the stack has a limitted size.  Instead it may be a good idea to create the array at run time.  This has the added advantage that you can specify the size as a variable instead of a constant (once you create it, the size is still constant) and it is created on the heap instead of on the stack which means that you have a lot larger storage size.  To do so use the new operator.

double* myArray = new double[arraySize];

afte that you can use the array just like any standard array.  Just don't forget to deallocate it when you are done.

delete [] myArray;

-gkatz
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now