fopen giving error

Discussion in 'C' started by infyanurag, Aug 4, 2009.

  1. infyanurag

    infyanurag New Member

    Joined:
    Aug 4, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi all

    I am trying to open a .par file with the help of fopen but the file is not getting opened.
    parfilename is passed as an argument to this, the value is domcol.par.
    The domco..par is resiging in same path as the code.

    FILE *parafile;
    parafile=fopen(parfilename,"rb");
    if (!parafile) {
    printf("error");
    }

    I am geeting error.
    kindly let me know as how to proceed with this.

    Thanks
    Anurag
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    Try :

    Code:
    FILE *parafile;
    parafile=fopen(parfilename,"rb");
    if (parafile==NULL) {
    printf("error");
    }
    
     
  3. infyanurag

    infyanurag New Member

    Joined:
    Aug 4, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I am getting error as output.
    But why?
    parfilename is domcol.par and i could see that.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    > The domco..par is resiging in same path as the code.

    OK, but is the file in the current directory, i.e. where you are now? A NULL return from fopen usually means the file can't be found. If it's not in the current directory then you need to include the full path to the file, and if it's in the same directory as the file then you can get the location from argv[0].

    Saswat: if (!parafile) and if (parafile==NULL) are equivalent.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice