strange fopen behaviour

This is a discussion on strange fopen behaviour within the C Programming forums, part of the General Programming Boards category; Hi, Can anyone say what may cause the following? I'm using fopen to open a file in read mode say ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    141

    strange fopen behaviour

    Hi,

    Can anyone say what may cause the following?

    I'm using fopen to open a file in read mode say test.txt. It reads it successfully but then it cannot open any other file with any other name/extension. Also,
    when I copy other files' data into test.txt it doesn't read the new data at all! I tried closing the program and recompiling it but in vain! When I ran it, it again showed the stale data of the initial test.txt file that it could read!

    Please advise.

    Thanks,
    AK

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    India
    Posts
    515
    Did you close the file stream using fclose() ??
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > It reads it successfully but then it cannot open any other file with any other name/extension
    Well if you fopen() in a loop, and don't close it, then you soon run out of available file handles.

    Code:
    if ( fopen("foo","r") == NULL ) {
      perror("oops");
    }
    Use perror() to tell you WHY the file could not be opened.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange behaviour of scanf()
    By chris1985 in forum C Programming
    Replies: 3
    Last Post: 01-15-2005, 01:41 PM
  2. strange behaviour of sscanf
    By BeBu in forum C Programming
    Replies: 7
    Last Post: 12-17-2004, 09:12 AM
  3. GetClientRect strange behaviour
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 10-02-2002, 02:13 PM
  4. Strange behaviour
    By PrivatePanic in forum Windows Programming
    Replies: 11
    Last Post: 07-23-2002, 12:54 AM
  5. strange behaviour by rhide
    By ustuzou in forum C++ Programming
    Replies: 0
    Last Post: 03-17-2002, 10:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21