Thread: For Loop Acting Goofy

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    4

    [SOLVED] For Loop Acting Goofy

    Trying to make a simple app to output a range of characters to a text file. This is the code:

    Code:
    #include <iostream>
    #include <fstream>
    int test[221];
    
    int main ()
    {
    	std::ofstream ascii_file ( "ascii.txt" );	
    	if ( !ascii_file.is_open() )
    	{
    		std::cout<<"File could not be opened.\n";
    		std::cout<<"Press enter key to exit...";
    		std::cin.get();
    		return 0;
    	}
    
    	ascii_file<<"ASCII Characters\n";
    	ascii_file<<"----------------\n";
    
    	for ( int i = 179; i <= 220; i = i + 6 )
    	{
    		test[i] = i;
    		/*
    		std::cout<<test[i]<<": "<<(char)test[i]<<" ";
    		std::cout<<test[i]++<<": "<<(char)test[i]<<" ";
    		std::cout<<test[i]++<<": "<<(char)test[i]<<" ";
    		std::cout<<test[i]++<<": "<<(char)test[i]<<" ";
    		std::cout<<test[i]++<<": "<<(char)test[i]<<" ";
    		std::cout<<test[i]++<<": "<<(char)test[i]<<"\n";
    		*/
    		ascii_file<<test[i]<<": "<<(char)test[i]<<" ";
    		ascii_file<<test[i]++<<": "<<(char)test[i]<<" ";
    		ascii_file<<test[i]++<<": "<<(char)test[i]<<" ";
    		ascii_file<<test[i]++<<": "<<(char)test[i]<<" ";
    		ascii_file<<test[i]++<<": "<<(char)test[i]<<" ";
    		ascii_file<<test[i]++<<": "<<(char)test[i]<<"\n";
    	}
    	ascii_file.close();
    	std::cout<<"File written successfully.\n";
    	std::cout<<"Press enter key to exit...";
    	std::cin.get();
    	return 0;
    }
    And this is the unexpected output:

    Code:
    ASCII Borders
    -------------
    179: ³ 179: ´ 180: µ 181: ¶ 182: · 183: ¸
    185: ¹ 185: º 186: » 187: ¼ 188: ½ 189: ¾
    191: ¿ 191: À 192: Á 193: Â 194: Ã 195: Ä
    197: Å 197: Æ 198: Ç 199: È 200: É 201: Ê
    203: Ë 203: Ì 204: Í 205: Î 206: Ï 207: Ð
    209: Ñ 209: Ò 210: Ó 211: Ô 212: Õ 213: Ö
    215: × 215: Ø 216: Ù 217: Ú 218: Û 219: Ü
    I can't seem to get the numbers to orient themselves correctly. Any help would be appreciated.
    Last edited by Austaph; 12-02-2005 at 06:17 PM. Reason: Fixed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Goofy .......... first lady has no etiquette
    By abachler in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 04-10-2009, 11:29 AM
  2. Is my compiler acting up?
    By Alastor in forum C Programming
    Replies: 10
    Last Post: 10-11-2005, 07:19 PM
  3. char[] acting weird
    By Leeman_s in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2003, 06:45 PM
  4. vectors acting up?
    By hsv in forum C++ Programming
    Replies: 1
    Last Post: 06-04-2003, 04:45 AM
  5. Goofy getline
    By Cela in forum C++ Programming
    Replies: 2
    Last Post: 01-16-2003, 02:43 PM