a small help

This is a discussion on a small help within the C Programming forums, part of the General Programming Boards category; hi Question: Using C could I open any file on my computer...........I was trying out this but it only worked ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    21

    Question a small help

    hi

    Question:

    Using C could I open any file on my computer...........I was trying out this but it only worked with the file saved in the dirctory...........

    I tried to open a file on some different directory but it again redulted in "Cannot open file"

    I also gave the full path of the file like:

    fp=fopen("d:\\programs\\try1.c","r");


    but it also didn't worked


    I would be thankful if u help me out of this mess.........

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Is your directory name more than 8 characters long?

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    From your other message
    > I've installed turboc 3.0

    This is an old compiler (really old) - you will have trouble accessing files if your operating system is win9x, NT, 2K, etc.

    You will have this problem if
    - any part of the path is a long filename
    - any part of the path contains spaces (or any other char which DOS disallowed)

    For instance, my "Program Files" directory has both a space, and is a long name. If I use explorer to look at the properties of this directory, I see the DOS filename is "PROGRA~1".

    If this is your case, then try
    fp=fopen("d:\\progra~1\\try1.c","r");

    Code:
    fp=fopen("d:\\programs\\try1.c","r");
    if ( fp == NULL ) {
        perror( "Cannot open file" );  // find out why
        exit( 1 );
    }
    As you seem to have access to vc++, I'd stick with that, because you're going to find more things wrong with that old compiler (wrong because its on the wrong operating system).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to split long programe in small files
    By umeshjaviya in forum C Programming
    Replies: 11
    Last Post: 04-15-2008, 02:45 AM
  2. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 01:05 AM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  4. yhatzee, small straight
    By uglyjack in forum C++ Programming
    Replies: 2
    Last Post: 06-13-2002, 03:09 AM
  5. Small app ideas
    By dirkduck in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 02-15-2002, 07:57 PM

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