Need help with opening a file in msdos

Discussion in 'C' started by lpd1, Feb 7, 2007.

  1. lpd1

    lpd1 New Member

    Joined:
    Feb 7, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi

    I am programming in c++ and i want to open a .xml file but i want the user to by himself enter the name of thefile he wants to open can someone please tell me what code i should use or even maybe print it in a reply to me thanks

    lpd1
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,374
    Likes Received:
    388
    Trophy Points:
    83
    You should use the scanf to take the input as filename and use the fopen to open the file and fread to read the file and display it to the user.
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    I presume you mean console/command window when you say "MSDOS". If not, you have an ancient system whose utility in learning will be minimal.

    You can get the name from argv if the user provides it on the command line. Since you're using C++, I would recommend you forego C operations like fopen, fgets, scanf, and fread. Use the C++ wrapped stream I/O for greater flexibility and robustness.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice