How would I check whether the input filename the user entered exists?

This is a discussion on How would I check whether the input filename the user entered exists? within the C Programming forums, part of the General Programming Boards category; How would I check whether the input filename the user entered exists? I need to create a program where a ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    244

    How can I verify that the input filename the user entered (to read from) exists?

    How would I check whether the input filename the user entered exists?

    I need to create a program where a very tiny part of it is making sure that the filename the user wants to read from exists, and if it does not exist, i need to reprompt the FILENAME scan command until the user enters a valid filename.


    Thanks in advance for the help.
    Last edited by matthayzon89; 11-05-2010 at 01:59 PM. Reason: unclear title
    Linklists use recursion to store what? ..... floats!

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438

    file

    to me that is just the same as your regular file open check, if it cant be opened (in read mode of course) then output your error and reprompt. a while loop can be used to loop until valid
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    have you read up on fopen and what it returns if it fails?

    fopen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to read a txt file into an array
    By Hitsugaya_KK in forum C Programming
    Replies: 49
    Last Post: 08-22-2009, 03:22 PM
  2. I have some questions :(
    By geekrockergal in forum C Programming
    Replies: 19
    Last Post: 02-01-2009, 09:44 AM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 12:09 PM
  4. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 04:32 PM
  5. Getting user input for filename loop
    By jpchand in forum C++ Programming
    Replies: 1
    Last Post: 09-16-2003, 07:37 AM

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