Thread: problem in opening a txt file

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    183

    Question problem in opening a txt file

    Hello
    I have downloaded a code from net which in one part, it works with files.
    here is some lines of that code
    Code:
        char *cfilename=0;
        char *rfilename[1];
              .
              .
              .
    
        if (cfilename==0) 
            cfilename=argv[i];
        else 
            rfilename[ref++]=argv[i];
              .
              .
              .
    
      FILE *fd=fopen(cfilename,"r");
      if (fd==NULL) 
      {
        fprintf(stderr,"Error reading %s\n",cfilename);
        return -1;
      }
      else
      {
              .
              .
              .
    my problem is that, it cann't open the file
    I have two txt files in the same directory (written in notepad and saved as unicode) named "cFileU" and "rFileU".
    I set the arguments: cFileU rFileU

    can you plz tell me what I should do to make it open the files?!!

    Thank you

  2. #2
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    What does your compiler tell you? If there are no errors, then I would suggest debugging the program to find the problem.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    1. Are you aware this is C, not C++? (C++ uses fstreams for files.) (Edit: I suppose I should mention that C++ will compile this C code without complaint, but it has been more-or-less replaced in the C++ language.)

    2. Do your files have extensions? (Hint: If you wrote them in notepad, the answer is "yes".)
    Last edited by tabstop; 06-07-2009 at 08:29 AM.

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    183
    Thank you
    I set the arguments: cFileU.txt rFileU.txt and the problem solved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 10:47 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM