Thread: File

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    46

    File

    Hi
    I want to open a file like:

    FILE *fp;
    fp=fopen("c:\\leite.txt","w+");

    My question is if i want to open the file like this;

    Ansistring FileName;
    FileName="leite.txt"

    fp=fopen("c:\\"+FileName,"w+");

    Something like this, i want to use outside AnsiString variable and then use it on fopen how i can do it???

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well with a std::string, it would be

    std::string filename = "file.txt";
    std::string = "c:\\" + filename;
    fp = fopen( filename.c_str(), "w+" );

    Does your ansiString come with a suitable method to return a const char * equivalent?
    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.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    46
    Hi
    i did something like this but dont work:

    FILE *fp;

    AnsiString FileName;

    FileName=Edit1->Text;
    FileName="c:\\"+FileName;

    fp=fopen(FileName.c_str(),"w+");
    fclose(fp);

    What i have to change??? Help..... Do i have to use AnsiString and make it Char???

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Leite33
    Hi
    i did something like this but dont work:
    be more specific

    what interface AnsiString provides?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Does your ansiString come with a suitable method to return a const char * equivalent?
    Hint - this means you should go RTFM and find out what the API of ansiString is.
    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.

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    It's been a while since I used C++ Builder, but I believe AnsiString provided the c_str() function which returns a const char *. You shuold be able to press F1 and check what functions it provides to get a const char * back.

    If that isnt the problem then you have to be more clear about what "doesnt work".
    Just saying something doesnt work helps us nothing. it doesnt compile? the program crashes? no file is generated? what?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM