Re: cant figure out where the [segmentation] fault lies ??
From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 09/24/05
- Next message: Simon Morgan: "Validating multibyte strings"
- Previous message: Pascal Bourguignon: "Re: cant figure out where the [segmentation] fault lies ??"
- In reply to: ebrahimbandookwala_at_gmail.com: "cant figure out where the [segmentation] fault lies ??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 24 Sep 2005 01:59:54 -0400
In article <1127540245.240039.71820@g14g2000cwa.googlegroups.com>,
ebrahimbandookwala@gmail.com wrote:
> Hi Im making this fairly simple c prog which reads and writes structs
> to a file in binary . I get this stupid error when I try doing the
> following ( in deleteentry () )
>
> if(remove (filename))
> {
> if(rename (tempfile , filename))
> {
> if(!remove (tempfile))
> printf("\nFailed to remove %s" , tempfile);
> }
> else
> printf("\nFailed to rename %s" , tempfile);
> }
> else
> printf("\nFailed to remove %s" , filename );
>
> which fails at either the first level or the second. Cant figure out y
> ?? For some reason it refuses to delete the file (filename) . I also
> tried plain and simple rename(tempfile -> filename) but that too
> refuses to work ?? Maybe im overlooking something really stupid !! ..
remove() and rename() return 0 when they're successful. 0 is false when
used in an if(). So I think the sense of your tests are backward. You
want something like
if(remove(filename) == 0)
-- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***
- Next message: Simon Morgan: "Validating multibyte strings"
- Previous message: Pascal Bourguignon: "Re: cant figure out where the [segmentation] fault lies ??"
- In reply to: ebrahimbandookwala_at_gmail.com: "cant figure out where the [segmentation] fault lies ??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|