Thread: Help with streams

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    29

    Help with streams

    Why dose this not work:
    Code:
    char array[20][26];
    ifstream arrayfile ( name );
    if (arrayfile.fail())
     {
            	cout << "Problems opening "<<name<< endl;
            	kill (1);
     }
    
    int xx = 0;
    int yy = 0;
    while ( xx != 26 )
    {
                    while ( yy != 20 )
                    {
                            arrayfile>>array[yy][xx];	
    			yy++;
    		}
    		xx++;
    		yy = 0;
    }
    output in array:
    Code:
    22222222222222222222
    22222220000000000000
    00000000000220000001
    00000000000000000220
    00011111011111111100
    00022000011100000000
    11110000022000011100
    00000011110000022000
    01110000000011110000
    02200001110000001011
    11000002200001110001
    00001111000002200071
    11000000001111000002
    20000111000010001111
    00004220000111000000
    00111100000220000111
    00000000111100000220
    00011111111111111100
    00022000011111111111
    11110000022000111111
    11111111110000022000
    00000000000000000000
    02200000000000000000
    00000002200000000000
    00000000000002222222
    22222222222222222222
    when the reverse works fine:
    Code:
    void array_to_file ( int array[20][26], char name[50] )
    {
    	ofstream arrayfile ( name );
    	if (arrayfile.fail())
            {
            	cout << "Problems opening "<<name<< endl;
            	kill (1);
            }
    
    	int xx = 0;
    	int yy = 0;
    	while ( xx != 26 )
    	{
    		while ( yy != 20 )
    		{
    			arrayfile<<array[yy][xx];	
    			yy++;
    		}
    		xx++;
    		arrayfile<<endl;
    		yy = 0;
    	}
    	arrayfile.close();
    }
    output in file:
    Code:
    22222222222222222222222222
    20000000000000000000000002
    20000001000000000000000002
    20000111110111111111000002
    20000111000000001111000002
    20000111000000001111000002
    20000111000000001111000002
    20000111000000101111000002
    20000111000100001111000002
    20007111000000001111000002
    20000111000010001111000042
    20000111000000001111000002
    20000111000000001111000002
    20000111111111111111000002
    20000111111111111111000002
    20001111111111111111000002
    20000000000000000000000002
    20000000000000000000000002
    20000000000000000000000002
    22222222222222222222222222
    How can it be done corectly?

    the app is the attachment its a linux 32bit binery that depends on liballegro-4.9.12.so.
    Last edited by IM back!; 08-09-2009 at 05:32 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing to two streams: va_arg issues
    By dwks in forum C Programming
    Replies: 2
    Last Post: 09-26-2007, 10:14 AM
  2. input/output streams
    By cybernike in forum C++ Programming
    Replies: 2
    Last Post: 08-07-2007, 11:15 PM
  3. dumb question about streams
    By terracota in forum C++ Programming
    Replies: 7
    Last Post: 07-06-2004, 12:14 PM
  4. Independent streams of pseudo random number generator
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-15-2001, 05:32 AM
  5. File Streams, new error on me.
    By Eber Kain in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2001, 08:28 PM