Novice needing help PLEASE!!!!!

This is a discussion on Novice needing help PLEASE!!!!! within the C++ Programming forums, part of the General Programming Boards category; Ok here is my situation. I am realy new to this stuff and dotn know crap to tell you the ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    19

    Unhappy Novice needing help PLEASE!!!!!

    Ok here is my situation. I am realy new to this stuff and dotn know crap to tell you the truth. But her eis my situation

    Here is my code:

    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <stdlib.h>
    #include <string.h>
    
    void main()
    {
      ifstream inFile;
      ofstream outFile;
      char myInFile[20] = "a:\\input.txt"; // The inout file.
      char myOutFile[20] = "a:\\output.txt"; // The output file.
    
      inFile.open(myInFile);
    
      if(inFile){
        cout << "\nInput file " << myInFile << " was succesfully opened!!!!"
             << endl;
      } else {
        cout << "\nInput File " << myInFile << " could not be opened!!!!"
             << endl;
        exit(-1);
      }
    
      outFile.open(myOutFile);
    
      if(outFile){
        cout << "\nOutput file " << myOutFile << " was succesfully opened!!!!"
             << endl;
      } else {
        cout << "\nOutput File " << myOutFile << " could not be opened!!!!"
             << endl;
        exit(-1);
      }
    
      
      int account =0;
      char fName[20];
      char lName[20];
      float amount =0;
      char dummy;
     
      outFile << "This is the data that was read in." <<endl <<endl;
    
      inFile >> account >> fName >> lName >> amount; // Prime Read
    
      while(inFile){
    
    
         outFile << account << ' ' << fName << ' ' << lName
                         << ' ' << amount << endl;
    
         inFile >> account >> fName >> lName >> amount;
    
      } //while
    
      outFile << "\nThe end of the input!!!";
      
    }
    It reads in this file:


    1001
    Mary
    Gist
    12350.123
    1002
    John
    Smith
    2600.2291
    1003
    Nick
    Dillon
    271623.98
    1004
    Brad
    Frazier
    72.19
    1005
    Chris
    Parish
    81625.00
    1006
    Robin
    Payne
    1200.34
    1007
    Jamie
    Lampe
    961.80
    1008
    Melanie
    Dixon
    62199.71
    1009
    Terrance
    Henderson
    3928.10
    1010
    Mark
    Cooper
    1.25


    And spits out this:


    This is the data that was read in.

    1001 Mary Gist 12350.1
    1002 John Smith 2600.23
    1003 Nick Dillon 271624
    1004 Brad Frazier 72.19
    1005 Chris Parish 81625
    1006 Robin Payne 1200.34
    1007 Jamie Lampe 961.8
    1008 Melanie Dixon 62199.7
    1009 Terrance Henderson 3928.1
    1010 Mark Cooper 1.25

    The end of the input!!!


    Now what i have to do is make the output file print in alphabetical order by last name!!!

    I dont know what to do.
    Should i use qsort or what and how

    Please help!!! THANK YOU!!!!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    First, don't use void main, it's wrong.
    int main() is correct.

    Second, this is nonportable:
    >exit(-1);
    The main function returns an int, but only three values are guaranteed to work on all systems that support C++. Those values are 0, EXIT_SUCCESS, and EXIT_FAILURE. Granted, you can return whatever you want but if it isn't one of those values you can't be sure that it will work.

    Third, if you are allowed to use qsort then by all means do so. It's the simplest way. Or you can look into the C++ sort function in <algorithm>. For details on qsort, go here:
    http://www.cprogramming.com/cboard/s...ighlight=qsort
    It only works on doubles in this example, but you can easily modify it for strings.

    I imagine you will have further questions, but I won't tell you why. You'll find out.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Novice needing help!
    By mc82 in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2008, 04:03 PM
  2. Replies: 10
    Last Post: 06-17-2005, 10:00 PM
  3. Rtfm
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-13-2003, 04:19 PM
  4. help for a C novice
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 05-02-2002, 09:49 PM

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