CoolInterview.com - World's Largest Collection of Interview Questions
Start Your Own website Now
Sponsored Links

Interview Questions
Our Services

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies


  • INTERVIEW QUESTIONS C POINTERS IN C DETAILS
    Question :
    What is file pointer and its working method?

    Posted by: mohan on 11/27/2007

    Contact mohan Contact mohan
    Category Pointers in C Interview Questions
    Rating (0.4) By 1686 users
    Added on 11/27/2007
    Views 3824
    Rate it!
    Answers:

    when a pointer is pointing to the address of a file than it is called as a file pointer.
    for example:
    FILE *fp;
    here in above statement we are declaring a file pointer.
    there are many modes of opening a file.they are read ,write,append ..
    they are as follows..
    fp=fopen("filename.c",'r');
    above statement is opening a file in read mode..



    Posted by: kishore reddy    

    Contact kishore reddy Contact kishore reddy

    C communicates with files using a new data type called a file pointer. This type is defined within stdio.h, and written as FILE *. A file pointer called output_file is declared in a statement like


    FILE *output_file;



    Posted by: Milind Kotibhaskar    

    Contact Milind Kotibhaskar Contact Milind Kotibhaskar

    Basically a file pointer is capable to store address of a file which is created by fopen function.Using this pointer we can do operations(read,write,modify) on the file.



    Posted by: SYED AMIDUL ISLAM    

    Contact SYED AMIDUL ISLAM Contact SYED AMIDUL ISLAM

    File pointer is the pointer which holds the address of the file which is opened either in read or write or append or binary modes(r,w,a,r+,w+,a+,b).

    FILE *fp;

    This is the declaration of the file pointer.

    Opening of the file is done by any one of the following.

    fp = fopen("filename.txt","r"); or
    fp = fopen("filename.TXT","w"); or
    fp = fopen("filename.DAT","a"); or
    fp = fopen("filename","r+"); or
    fp = fopen("filename.txt","w+"); or
    fp = fopen("filename.txt","a+"); or
    fp = fopen("filename.txt","b");

    When fopen opens the file successfully, fp holds the address of the first character in the file.

    We can read or write into the file using the functions like fread() or fwrite().

    After all operations, we have to close the file using fclose(fp);



    Posted by: Syed Baseer Ahmed    

    Contact Syed Baseer Ahmed Contact Syed Baseer Ahmed

    File pointer is a pointer which is used in file handling through file pointer we can open the file in write mode and read mode and also closed the file through file pointer.



    Posted by: mohit kumar    

    Contact mohit kumar Contact mohit kumar

    A special data type for handling files is defined in the stdio.h header file.

    It is called the file pointer and has the syntax FILE*.

    File pointers are used to open,read,write and close files.


    FILE *file_ptr;
    file_ptr=fopen("data.txt","w");

    It is advisable to test the file pointer against NULL value if we get back NULL the actual operation /with the file/ has failed.

    #include <stdio.h>

    int main()
    {

    FILE *file_ptr;
    file_ptr=fopen("data.txt","w");

    if (file_ptr!=NULL)
    {
    printf("file created
    ");
    fclose (file_ptr);
    return 0;
    }
    else
    { printf("unable to create file
    ");
    return 1;

    }
    }



    Posted by: Andrew Gecse    

    Contact Andrew Gecse Contact Andrew Gecse

    When file is opened, the pointer points to the first character in the file.

    My doubt is, suppose a file contains a word Happy.
    I want to know the position of a. How to get that.

    I tried this #include<stdio.h>
    #define NULL 0
    void main()
    {
    FILE *fp=NULL;
    char s[20];
    fpos_t pos;
    if((fp=fopen("catalog.txt","r"))==NULL)
    printf("Catalog error ");
    printf("Po of fp:%p",fp);


    while(!feof(fp))
    {


    fgets(s,sizeof(s),fp); /*Read a line from file*/
    printf(" Postion of fp: %p",fp);
    }
    }

    But the address of the pointer is same, It is reading all the lines from the file, but the address value is same?

    Please help me on this.



    Posted by: Subbs    

    Contact Subbs Contact Subbs

    If you have the better answer, then send it to us. We will display your answer after the approval.
    Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       
    Related Questions
    View Answer
    How I can add two numbers in c language without using Arithmetic operators?
    View Answer
    What is pointer?
    View Answer
    What are the disadvantages of using Pointers.
    View Answer
    How to operate pointers in any pragram & how to develop our logic while implementing pointer
    View Answer
    Difference between arrays and pointers?

    View Answer
    What is the difference between NULL and NUL?


    View Answer
    What is a null pointer?


    View Answer
    What is a const pointer?
    View Answer
    What is pointer?

    View Answer
    What do you mean by normalisation of pointers

    View Answer
    Following declarations are same
    const char *s;
    char const *s;


    View Answer
    In the following code, what is p2?

    typedef int* ptr

    ptr p1, p2;




    View Answer
    In the following code, what is p2?

    typedef int* ptr

    ptr p1, p2;




    View Answer
    What is far pointer?

    View Answer
    Between a long pointer and a char pointer , which one consumes more memory? explain

    View Answer
    How reliable are floating-point comparisons?
    View Answer
    What is indirection?
    View Answer
    How many levels of pointers can you have?
    View Answer
    What is a null pointer?
    View Answer
    What is a void pointer?
    View Answer


    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL Pointers in C Interview Questions

    User Options
    Sponsored Links


    Copyright ©2003-2014 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions

    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | C Interview Questions & Answers

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes


    Cache = 0 Seconds