Thread: Allocate memory for an Array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    385

    Allocate memory for an Array

    I am trying to run this code below after I have compiled in C++.
    The code do succesful when compiling.

    When I doubleclick the program it starts but immediately the program encounters a problem and closes again.
    What the code does is to read in values from a .txt file in arrays. As seen the arrays I am using has values like: Timearr[100000] etc...
    If I change these to 10000 instead the program works and no problem occurs.

    Could there be any idéas why this is happening ?
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    #include <sstream> 
    #include <string>  
    
    using namespace std;
    int main () 
    { 
    	std::string Datee;
    	char Comma;
    	int Timee = 0;
    	
    	std::string Datearr[100000];
    	int Timearr[100000];
    	int CountArray = 100000;
    
    	ofstream MainFile;
    	MainFile.open ("MainFile.txt");
    	ifstream stockfile ("CCE.txt");
    			
    	while	(    getline(stockfile, Datee, ',')   )           		
    	{
    		
    		stockfile >> Timee;		       
    		stockfile >> Comma;                   
    		stockfile.get();				// read in trailing newline character
    	//////////////////////////////////////////////////////////////////////		
    	// Read in File into Arrays (The Code is running now)
    	
    
    		CountArray = (CountArray - 1);	// CountDown for CountArray while all values is inserted for the arrays
    		Datee = Datearr[CountArray];
    		Timee = Timearr[CountArray];
    		
       }							// End of While Statement
    	//////////////////////////////////////////////////////////////////////		
    	
    
    		return 0;
    }			// int main braces
    Last edited by Coding; 01-05-2008 at 05:45 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  2. Array of strings and memory allocation
    By maluyk in forum C Programming
    Replies: 7
    Last Post: 01-26-2009, 11:52 AM
  3. Replies: 2
    Last Post: 05-10-2005, 07:15 AM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM