Thread: File

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    13

    File

    Hello, I am writing this code with Borland C. The problem is that when I try to find the .txt file, I see that it hasnīt been created.Then dubugging it, I see stream=NULL. Can anyone help me?
    Code:
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
      #include <string.h>
    #include <io.h>
    #include <iostream.h>
    #include <dstring.h>.
    #include <stdio.h>
    #include <math.h>
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    
    
    
    using namespace std;
    
    
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    AnsiString FN;
    
    //Text1 = Text2
    FN=Edit1->Text;
    
    Edit2->Text=FN;
    
    
    //Creation of the file
    FILE *stream;
      
       stream = fopen("c:\log.txt", "w+");  
       fprintf(stream, "All is right");
       fclose(stream);
    
    
    }
    //---------------------------------------------------------------------------
    Thanks,

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You have to escape backslashes in strings. Try:

    "c:\\log.txt"

    Also, this is C++ code, so it should have been posted on the C++ board.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Moved to C++ forum

    > #include <io.h>
    This is a DOS header file

    > #include <iostream.h>
    But you're using namespaces later on, so it should be
    #include <iostream>

    > #include <stdio.h>
    This is a C header file.

    First thing you need to do is decide which OS and Language you're actually programming in.
    It looks like C/C++ for Win/DOS (this is never going to be pretty).
    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.

  4. #4
    Registered User
    Join Date
    Jul 2005
    Posts
    13
    Sorry, for wrote it in C, it was a slip. Thanks quzah, it worked. Salem, I take it into account, and Iīll try to write a better code.

    thanks!,

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