LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2004, 11:37 PM   #1
skywalker27182
Member
 
Registered: Nov 2003
Posts: 35

Rep: Reputation: 15
why FILE* fp? why not FILE fp?


hi everybody,
my question is: why do we always use FILE * and not just FILE while declaring a file pointer
 
Old 07-07-2004, 01:03 AM   #2
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
We always use FILE * because the function fopen returns a file pointer . So to collect the returned value, which is an address, we use a file pointer.
 
Old 07-07-2004, 02:48 AM   #3
skywalker27182
Member
 
Registered: Nov 2003
Posts: 35

Original Poster
Rep: Reputation: 15
so, will the following work?

Code:
main()
{
    ...

    FILE fp;
    &fp = fopen(...);

    ...
}
 
Old 07-07-2004, 10:25 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
No, C doesn't allow that kind of lvalue. I suggest you read up on pointers. What they are and where/why they're useful.
 
Old 07-07-2004, 04:36 PM   #5
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
In other words,
we declare a FILE *fp because when we call fopen a FILE is created in memory, so we use the *fp to reference it from our code.

As you can see from fopen's declaration:

FILE *fopen(const char *path, const char *mode);

" FILE *fopen " means it returns a pointer to type FILE, so as I said above,
we declare a FILE *fp so we can use that pointer.
 
Old 07-07-2004, 11:03 PM   #6
skywalker27182
Member
 
Registered: Nov 2003
Posts: 35

Original Poster
Rep: Reputation: 15
okkk, understood. thanks all for ur replies. will read up on pointers.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
forrtl: severe (47): write to READONLY file, unit 5, file /dev/pts/1 terrence Programming 1 10-01-2005 10:22 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
libawt.so: libXp.so.6: cannot open shared object file: No such file or directory man26 *BSD 0 09-10-2004 08:34 AM
Yum update complains missing file (broken dep), but file can be located. davidas Linux - Software 0 03-27-2004 09:11 PM
How to play a media file/ video file/mp3 file recorded in harddisk/cd-rom arindam Linux - Newbie 2 09-05-2003 10:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration