Reading chars from file into array

This is a discussion on Reading chars from file into array within the C++ Programming forums, part of the General Programming Boards category; Debug Error!: Run-time check failure #2 - stack around variable 'infile' was corrupted. weird info about this problem - the ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    30

    Reading chars from file into array

    Debug Error!: Run-time check failure #2 - stack around variable 'infile' was corrupted.

    weird info about this problem - the book says the file should be called RainOrShine.dat but my computer says its called RainOrShine.txt. I tried both... the .txt will cout some of the chars from file but then the error comes up. the .dat compiles and doesn't get an error but returns trash values for cout.

    here is code:

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main()
    {
    	ifstream infile;
    	infile.open("RainOrShine.txt");
    
    	char weather[3][30];
    
    	for (int i = 0; i < 3; i++)
    	{
    		for (int j = 0; i < 30; i++)
    		{
    			infile >> weather[i][j];
    			cout << weather[i][j];
    		}
    	}
    
    	infile.close();
    
    	
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Code:
    for (int j = 0; i < 30; i++)
    Take a very careful look at that line of code.
    bit∙hub [bit-huhb] n. A source and destination for information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help - Reading a file and storing it as a 2d Array.
    By MetallicaX in forum C Programming
    Replies: 2
    Last Post: 03-08-2009, 08:33 PM
  2. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  3. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-22-2008, 12:19 AM
  4. Reading from a file into an array
    By fmsguy06 in forum C Programming
    Replies: 6
    Last Post: 10-18-2008, 10:25 PM
  5. Reading in an array of text from a file?
    By suzakugaiden in forum C++ Programming
    Replies: 6
    Last Post: 01-04-2006, 03:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21