Whats wrong with my program?(writing data into a file)

This is a discussion on Whats wrong with my program?(writing data into a file) within the C++ Programming forums, part of the General Programming Boards category; #include <iostream.h> #include <fstream.h> #include <stdio.h> #include <conio.h> #include <conio.c> #include <stdlib.h> #define say cout #define USHORT int void write_to_file(); ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    106

    Whats wrong with my program?(writing data into a file)

    #include <iostream.h>
    #include <fstream.h>
    #include <stdio.h>
    #include <conio.h>
    #include <conio.c>
    #include <stdlib.h>

    #define say cout
    #define USHORT int

    void write_to_file();
    typedef char ZOO;

    ZOO username[25];
    USHORT desiredlives;

    int main()
    {
    textcolor( 6 );
    say << "Input your player\'s name: ";
    cin >> username;

    say << "\nOk " << username << ". How many lives do you want to start with? ";
    cin >> desiredlives;

    say << "\nThanks, thats all of the information we need." << endl;
    say << "\n";

    write_to_file();
    getch();
    return 0;
    }

    void write_to_file()
    {
    ZOO player=username[25];
    USHORT lives=desiredlives;

    ofstream fout;

    fout.open("player.dat");

    fout << "Player: " << player;
    fout << "\nLives: " << lives;

    fout.close();
    }

  2. #2
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Well not including your non-adherance to the ANSI standard... this will do you...

    Code:
    #include <iostream.h> 
    #include <fstream.h>
    #include <conio.h>
    #include <string.h> 
    
    #define say cout 
    #define USHORT int 
    #define ZOO char
    
    ZOO username[25]; 
    USHORT desiredlives; 
    
    void write_to_file(); 
    
    int main() 
    { 
       say << "Input your player's name: "; 
       cin >> username; 
    
       say << "\nOk " << username << ". How many lives do you want to start with? "; 
       cin >> desiredlives; 
    
       say << "\nThanks, thats all of the information we need." << endl; 
       say << "\n"; 
    
       write_to_file(); 
       getch(); 
       return 0; 
    } 
    
    void write_to_file() 
    { 
       ZOO player[25];
       strcpy (player, username);
       USHORT lives=desiredlives; 
    
       ofstream fout; 
    
       fout.open("player.dat"); 
    
       fout << "Player: " << player; 
       fout << "\nLives: " << lives; 
    
       fout.close(); 
    }
    Blue

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 05:44 PM

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