[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

RE: c++ query



  Try to open the file after creating it.

The code which worked for me is here,
--------------
main()
{

  int fd;
  char filename[10];
  char text[]="Hello";

  scanf("%s", filename);

  close( 1 );

  creat ( filename, 0x666 );

  open( filename, O_WRONLY );

  printf("the printf is printing %s", text );

}
---------------------
-Thanks,
Syed Khaleelulla.
---------------


On Sat, 30 Sep 2000, Harpreet Singh (RBIN/DCA-NMP) wrote:

+This is what I am doing ....... but not getting the desired result
+
+int fd;
+
+close(2)
+
+close(1)
+
+fd = creat("test.txt",0777);
+
+printf("Hello World\n");
+
+close(fd);
+
+> -----Original Message-----
+> From:	Syed Khaleelulla [SMTP:Syed.Khaleelulla@xxxxxxxxx]
+> Sent:	Saturday, September 30, 2000 11:16 AM
+> To:	linux-india-programmers@xxxxxxxxxxxxxxxxxxxxx
+> Subject:	Re: [LIP] c++ query
+> 
+> Hello,
+>   There are different ways to do this.
+> 
+> One way is to close the file Discriptor 1, and then issue a open system
+> call with the filename as the one where the output has to be sent, the
+> open
+> system call will us the smallest fd avilable, [i.e. 1]. There by any
+> printf
+> command will send the output to the file which has been opened.
+> 
+> -Thanks,
+> Syed Khaleelulla.
+> --------------------
+> 
+> On Sat, 30 Sep 2000, Harpreet Singh (RBIN/DCA-NMP) wrote:
+> 
+> +Hi,
+> +
+> +Is there a way to close the standard output and reassign cout to point to
+> a
+> +file.
+> +( What I want to do is give an option to the user, if a file name has
+> been
+> +specified output should be written to the file else to the standard
+> output;
+> +and the user will be using cout )
+> +
+> +Thanks in advance
+> +
+> +
+> +
+> +
+> +
+> +---------------------------------------------
+> +LIP is all for free speech.  But it was created
+> +for a purpose.  Violations of the rules of
+> +this list will result in stern action.
+> +
+> 
+> **************************************************************************
+> *
+>              _.-.
+>          .-.  `) |  .-. 
+>      _.'`. .~./  \.~. .`'._
+>  .-'`.'-'.'.-:    ;-.'.'-'.`'-.
+>   `'`'`'`'`   \  /   `'`'`'`'`
+>               /||\
+>              / ^^ \   In the world without fence...   which need gates?
+> ************
+> `'``'`********************************************************
+> Syed Khaleelulla,                        26, Hosur Main Road, Bommanhalli,
+> Senior Software Engineer,                Bangalore - 560068, India.
+> Wipro Global R&D.                        Tel: 91-80-5722293/6 Extn- 2203.
+> **************************************************************************
+> *
+> 
+> 
+> ---------------------------------------------
+> Find out more about this and other Linux India
+> mailing lists at http://lists.linux-india.org/
+
+---------------------------------------------
+LIP is all for free speech.  But it was created
+for a purpose.  Violations of the rules of
+this list will result in stern action.
+

***************************************************************************
             _.-.
         .-.  `) |  .-. 
     _.'`. .~./  \.~. .`'._
 .-'`.'-'.'.-:    ;-.'.'-'.`'-.
  `'`'`'`'`   \  /   `'`'`'`'`
              /||\
             / ^^ \   In the world without fence...   which need gates?
************ `'``'`********************************************************
Syed Khaleelulla,                        26, Hosur Main Road, Bommanhalli,
Senior Software Engineer,                Bangalore - 560068, India.
Wipro Global R&D.                        Tel: 91-80-5722293/6 Extn- 2203.
***************************************************************************