Solved

Readinf file and parsing

Posted on 2003-11-29
1
258 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

756 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