Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-10-2013, 08:57 AM   #1
Registered: May 2013
Location: India
Distribution: Ubuntu 11.10
Posts: 178

Rep: Reputation: Disabled
Unhappy creating log file with rw+a then also contains i am sending to file are not appnded

fp = fopen ("/home/ivb/rohan/files/log/desc_log.txt", "rw+a");

printf("log is created. . .\n");
printf("error in creating log. . .\n");
1. when i run the code at first run it doest create file with "rw+a"
2. i have to go n change it to w+ mode n run the code again then file gets created.
3. "rw + a" mode gives file creation error if i run it first time
4. appending the data doesnt really occures

whre i am making the mistake please give suggstion

Thanks & Regards
Old 05-11-2013, 06:47 AM   #2
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 200Reputation: 200Reputation: 200
fopen("blah", "a");
for appending.

man fopen

a Open for appending (writing at end of file). The file is created if
it does not exist. The stream is positioned at the end of the file.
1 members found this post helpful.
Old 05-11-2013, 07:17 AM   #3
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,316

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
Note: mode="a" (or O_APPEND with open) doesn't simply mean 'seek to the EOF after open', instead it means 'seek to the EOF before each write' -- that's how multiple processes can use the same log-file


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Log file to log activity time in Ubuntu mint nervous137 Linux - Newbie 4 04-19-2012 08:37 AM
[SOLVED] Sending Errors to Log File: Best Practice? blingham Linux - Newbie 3 07-24-2009 08:59 AM
creating a log file of users who are missing a file gd121462 Linux - Newbie 5 12-04-2008 04:54 AM
creating log file RudraB Programming 2 12-13-2007 12:35 AM
Creating the log-file dr_sad Programming 5 04-12-2005 06:01 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:32 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration