opening a file in DOS

This is a discussion on opening a file in DOS within the A Brief History of Cprogramming.com forums, part of the Community Boards category; How can I open another .exe file in my DOS-program....

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    17

    opening a file in DOS

    How can I open another .exe file in my DOS-program.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    46
    do you mean execute another exe or open it and view the content?

    system("MyProgram.exe"); will execute it, also look into the various spawn and exec functions

    otherwise:

    This code reads the contents of a file
    Code:
    FILE *fptr;  //file pointer
    
    fptr=fopen("MyFile.txt", "rb"); //open file as read binary mode
    
    while(YourMomIsFat)  //usually check for eof or something
    {
        variable=fgetc(fptr);  //read a byte
        UseVariableInSomeWay();
    }
    there are numerous other ways to read from a file but this is just one.
    mooooo@cooowwww.com

  3. #3
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    in c++
    Code:
    #include <iostream>
    #include <fstream>
    ...
    ofstream fout=("c:\\whatever\\new.txt");
    if (!fout.is_open())
    {
         cerr<<"Oops, file can't be created or opened."<<endl;
         exit(1);
    }
    fout<<"Some Text"<<endl;
    fout.close();
    
    ifstream fin=("c:\\whatever\\new.txt");
    if (!fin.is_open())
    {
         cerr<<"Oops, file can't be opened."<<endl;
    }
    fin>>someText;
    cout<<someText;
    fin.close();
    ...
    PHP and XML
    Let's talk about SAX

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    In English:
    Code:
    Open file.txt and read it.
    One line of code, the obvious best choice

    There are standard functions in C. All compilers are supposed to have them. Same deal with C++.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    46
    well duh!!! But thats not why hes asking, you cant expect someone to know all the standard c/c++ functions and understand exactly how to use them.
    mooooo@cooowwww.com

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    17
    Thanks people....
    I use Borland 5.02

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    29
    http://www.rt.com/man/execl.3.html

    There are several functions that allow you to excecute a file and are better to use than system("whatever.exe").

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    46

    Talking

    Do I hear an echo in here? Also, dont trust that include file, I dont think its dos standard.

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Originally posted by thedumbmutt
    well duh!!! But thats not why hes asking, you cant expect someone to know all the standard c/c++ functions and understand exactly how to use them.
    True, but I'd say that most people who have been programming for a while know a pretty good deal of them (if not all of them) and how to use those that they know of. The c standard library isn't a very big library.

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    46
    But he did ask, so that would suggest he needed some sort of help, examples are nice sometimes.
    mooooo@cooowwww.com

  11. #11
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You're good at picking nicknames, I'll give you that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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