LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   creating log file with rw+a then also contains i am sending to file are not appnded (https://www.linuxquestions.org/questions/programming-9/creating-log-file-with-rw-a-then-also-contains-i-am-sending-to-file-are-not-appnded-4175461423/)

rohaanembedded 05-10-2013 07:57 AM

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");

if(fp){
printf("log is created. . .\n");
}
else{
printf("error in creating log. . .\n");
er=1;
}
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
rohaan

bigearsbilly 05-11-2013 05:47 AM

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.

NevemTeve 05-11-2013 06:17 AM

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


All times are GMT -5. The time now is 09:23 AM.