Thread: FILE problem

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    8

    FILE problem

    Hi
    in this statement
    FILE *f1;
    f1=fopen("123456789.txt","w");

    here the pgm should open the named file if it exists or should create a new one right, but it just creates a file with only 8 characters in its name like 12345678.txt. why is it so. also i get an error if i try to open a file whose name is more than 8 chars. i want file with length of name to be opened.what to do

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    So your compiler is only supporting DOS (8.3) filenames. If you want longer filenames, you need to get a compiler that supports that - for Windows or Leopard or Linux, or BSD, etc.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Doron Moraz
    Guest
    Quote Originally Posted by Raghavan View Post
    Hi
    in this statement
    FILE *f1;
    f1=fopen("123456789.txt","w");
    here the pgm should open the named file if it exists or should create a new one right
    Using "w" will not only open the file if it already exist.
    It will open the file and truncate the file to zero length.
    If you are aware of that, that's fine, if you want to keep the file existing data, use "a" instead.

    Anyway, as mentioned before you might using a compiler that only support DOS 8.3 filenames. However if the compiler is running in a MS-DOS FAT file system environment upgrading the compiler will not allow you to use longer filenames.


    Regards
    Doron Moraz
    Last edited by Doron Moraz; 01-22-2008 at 02:30 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Rename file problem
    By Emporio in forum C Programming
    Replies: 2
    Last Post: 06-05-2002, 09:36 AM