FACTOID # 79: Australians are the most likely to join charities, educational organizations, environmental groups, professional organizations, sports groups and unions. But only three percent join political parties.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RELATED ARTICLES
People who viewed "Fopen" also viewed:
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Fopen
The title given to this article is incorrect due to technical limitations. The correct title is "fopen".

In computer programming, the fopen, with related functions fdopen and freopen, is one of the basic functions in the C programming language and also exists in various other computer languages such as PHP. They return a stream attached to the specified file from which reading and writing can be done. Because it is so popular, many script languages derived from C tend to provide the same function with the same or similar functionality. It is considered higher-level than the open system call of UNIX operating systems.


They are defined as.

FILE * fopen(const char *path, const char *mode);
FILE * fdopen(int fildes, const char *mode);
FILE * freopen(const char *path, const char *mode, FILE * restrict stream);

The fdopen function is not standard in C89 or C99, but is an extension used in POSIX environments and imitated elsewhere.


The mode parameter is a string that begins with one of the following sequences:

 r Open a text file for reading w Truncate file to zero length or create text file for writing a Append: open or create text file for writing at end-of-file rb Open a binary file for reading wb Truncate file to zero length or create binary file for writing ab Append: open or create binary file for writing at end-of-file r+ Open text file for update (reading and writing) w+ Truncate file to zero length or create text file for update a+ Append: open or create text file for update, writing at end-of-file r+b or rb+ Open binary file for update (reading and writing) w+b or wb+ Truncate file to zero length or create binary file for update a+b or ab+ Append: open or create binary file for update, writing at end-of-file 

The C standard gives two kinds of files: text files and binary files, although operating systems may or may not distinguish between the two. A text file is a file consisting of text arranged in lines with some sort of distinguishing end-of-line character or sequence (in Unix, a bare linefeed character; in the Macintosh OS, a bare carriage return; on DOS and Microsoft Windows, a carriage return followed by a linefeed). When bytes are read in from a text file, an end-of-line sequence is usually mapped to a linefeed for ease in processing. When a text file is written to, a bare linefeed is mapped to the OS-specific end-of-line character sequence before writing. A binary file is a file where bytes are read in "raw", and delivered "raw", without any kind of mapping.


A convenient way to find the length of a file in C is:

 FILE *f = fopen("filename", "rb"); fseek(f, 0, SEEK_END); length = tell(f); rewind(f); 

  Results from FactBites:
 
fopen can create or append a file (964 words)
fopen returns a pointer to be used to identify the stream in subsequent operations.
fopen also allows the t or b to be inserted between the letter and the + character in the mode string; for example rt+ is equivalent to r+t.
Because fopen() usually buffers the output, If the program were to crash, the log file would be incomplete and could mislead you about what the program was doing when it crashed.
fopen(3): stream open functions - Linux man page (796 words)
The fopen() function opens the file whose name is the string pointed to by path and associates a stream with it.
The fopen(), fdopen() and freopen() functions may also fail and set errno for any of the errors specified for the routine malloc(3).
The fopen() function may also fail and set errno for any of the errors specified for the routine open(2).
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.