LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 07-04-2004, 05:31 PM   #1
Nerox
Member
 
Registered: Jul 2004
Location: Spain
Posts: 111

Rep: Reputation: 20
Strange error calling fopen() twice


Hi, I have a little problem with the following code:
....
main(void){
FILE *fd = fopen("./file","a+");
if(fd == NULL){
perror("1st fopen");
fd = fopen("./file","w");
perror("2nd fopen");
}
}

I get the following output calling perror():

1st fopen: No such file or directory (OK!!)
2nd fopen: Illegal seek (What is THAT!?)

I also get the same error calling ftell(), for instance:

FILE *fd = fopen("./file","r");
fseek(fd,0,SEEK_END);
size = ftell(fd);
perror("ftell");

But both works.
Compiled with gcc 2.95.4 version.

Thanks.
 
Old 07-05-2004, 12:45 AM   #2
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
works for me.
 
Old 07-05-2004, 02:17 AM   #3
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
works for me too ........
gcc version 3.2.2
kernel 2.4.20-8
RH 9

Last edited by Kumar; 07-05-2004 at 02:19 AM.
 
Old 07-05-2004, 02:27 AM   #4
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
Do you have write permissions on the directory you are trynig to create the file in?
 
Old 07-05-2004, 08:27 AM   #5
Nerox
Member
 
Registered: Jul 2004
Location: Spain
Posts: 111

Original Poster
Rep: Reputation: 20
Yes, I have write permissions on that directory
 
  


Reply


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
odd recursion: calling "by hand" vs calling by cronscript... prx Programming 4 02-12-2005 05:59 PM
fopen() bcf2 Programming 3 12-23-2004 05:20 AM
fopen command not wroking in C strange alix123 Programming 2 11-16-2004 11:48 AM
return value from fopen when appending? linfan Programming 3 01-21-2004 02:21 PM
File Permission Error in PHP fopen() function tuka Linux - Software 2 08-12-2003 09:16 PM


All times are GMT -5. The time now is 04:39 AM.

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