Thread: reading a file,i have a problem with this

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    1

    Unhappy reading a file,i have a problem with this

    hi all

    i just write a code that read a string from list
    and when i run the program always give me that the name of file is not exists!

    here is the code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <windows.h>
    #define A 50
    
    typedef struct Lab *ptr;
    struct Lab{
    char Title[A];
    char Author[A];
    char Subject[A];
    long ISBN;
    ptr next;
    };
    typedef ptr LIST;
    typedef ptr Postion;
     void ReadFromFile(l);
    int main()
    {
        LIST l;
    l=(LIST)malloc(sizeof(struct Lab));
    l->next=NULL;
    ReadFromFile(l);
     
    return 0;
    }
      void ReadFromFile(LIST l){
       char reading[50];
       FILE*fin;
       printf("Enter the name of file");
       scanf("%s",reading);
       fin=fopen(reading,"r");
       if(fin == NULL){
        printf("the file not exsit");
       ReadFromFile(l);
       }
    else
        printf("okey");
       fclose(fin);
       }


  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What are you entering for the file name? Does that file actually exist in the projects working directory?

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with reading of file
    By skumarisation in forum C++ Programming
    Replies: 3
    Last Post: 05-28-2010, 06:01 AM
  2. problem with reading from file.
    By esi in forum C Programming
    Replies: 5
    Last Post: 06-23-2007, 02:50 PM
  3. file reading problem
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-19-2005, 08:58 AM
  4. Problem reading file.
    By Hulag in forum C Programming
    Replies: 11
    Last Post: 10-24-2004, 09:39 AM