Basic File I/O.... Can somebody help?

This is a discussion on Basic File I/O.... Can somebody help? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to get this simple File I/O code to work but it just outputs junk. Can anybody tell me ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    22

    Basic File I/O.... Can somebody help?

    I'm trying to get this simple File I/O code to work but it just outputs junk. Can anybody tell me what the problem is?

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <fstream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
      ifstream map(argv[1]);
      //cout<<argv[1];
      int height, width, length;
      int *numbers;
      char name[10];
      
      map>>name>>height>>width;
      length = width * height;
      numbers = new int[length];
      
      cout<<name<<"\n";
      cout<<height<<" x "<<width<<" = "<<length<<"\n";
      
      int n;
      
      for (n = 0; n < length; n++) {
        map>>numbers[n];
        numbers[n] -= 1;
        cout<<numbers[n]<<" ";
      }
      
      map.close();
      
      ofstream mapo("output.txt");
      
      cout<<"------------------------\n";
      
      for (n = 0; n < length; n++) {
        //cout<<numbers[n]<<" ";
        mapo<<numbers[n]<<" ";
      }
      
      mapo.close();
        
      system("PAUSE");
      return 0;
    }
    I've attached the input and output files.

    EDIT: Nevermind, I figured it out. Don't know how.... but I did.
    Attached Files Attached Files
    Last edited by Spitball; 07-24-2004 at 04:40 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM

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