Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1292698
  • 博文数量: 168
  • 博客积分: 2124
  • 博客等级: 大尉
  • 技术积分: 2590
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-16 23:51
文章分类

全部博文(168)

文章存档

2014年(6)

2013年(74)

2012年(71)

2011年(17)

分类: C/C++

2011-11-01 11:24:41

fgets

 


function
char * fgets ( char * str, int num, FILE * stream );

Get string from stream

Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or a the End-of-File is reached, whichever comes first.
A newline character makes fgets stop reading, but it is considered a valid character and therefore it is included in the string copied to str.
A null character is automatically appended in str after the characters read to signal the end of the C string.
 
fputs

function
int fputs ( const char * str, FILE * stream );

Write string to stream

Writes the string pointed by str to the stream.
The function begins copying from the address specified (str) until it reaches the terminating null character ('\0'). This final null-character is not copied to the stream.
 
fgetc

function
int fgetc ( FILE * stream );

Get character from stream

Returns the character currently pointed by the internal file position indicator of the specified stream. The internal file position indicator is then advanced by one character to point to the next character.
fgetc and getc are equivalent, except that the latter one may be implemented as a macro.
ParametersstreamPointer to a FILE object that identifies the stream on which the operation is to be performed.Return ValueThe character read is returned as an int value.
If the End-of-File is reached or a reading error happens, the function returns EOF and the corresponding error or eof indicator is set. You can use either ferror or feof to determine whether an error happened or the End-Of-File was reached.
 
fputc

function
int fputc ( int character, FILE * stream );

Write character to stream

Writes a character to the stream and advances the position indicator.
The character is written at the current position of the stream as indicated by the internal position indicator, which is then advanced one character.
ParameterscharacterCharacter to be written. The character is passed as its int promotion.streamPointer to a FILE object that identifies the stream where the character is to be written.Return ValueIf there are no errors, the same character that has been written is returned.
If an error occurs, EOF is returned and the error indicator is set (see ferror).
 
getc

function
int getc ( FILE * stream );

Get character from stream

Returns the character currently pointed by the internal file position indicator of the specified stream. The internal file position indicator is then advanced by one character to point to the next character.
getc is equivalent to fgetc and also expects a stream as parameter, but getc may be implemented as a macro, so the argument passed to it should not be an expression with potential side effects.
See getchar for a similar function without stream parameter.
Parametersstreampointer to a FILE object that identifies the stream on which the operation is to be performed.Return ValueThe character read is returned as an int value.
If the End-of-File is reached or a reading error happens, the function returns EOF and the corresponding error or eof indicator is set. You can use either ferror or feof to determine whether an error happened or the End-Of-File was reached.
 
putc

function
int putc ( int character, FILE * stream );

Write character to stream

Writes a character to the stream and advances the position indicator.
The character is written at the current position of the stream as indicated by the internal position indicator, which is then advanced one character.
putc is equivalent to fputc and also expects a stream as parameter, but putc may be implemented as a macro, so the argument passed should not be an expression with potential side effects.
See putchar for a similar function without stream parameter.
 
getchar

function
int getchar ( void );

Get character from stdin

Returns the next character from the standard input (stdin).
It is equivalent to getc with stdin as its argument.
 
putchar

function
int putchar ( int character );

Write character to stdout

Writes character to the current position in the standard output (stdout) and advances the internal file position indicator to the next position.
It is equivalent to putc(character,stdout).
 
 
ferror

function
int ferror ( FILE * stream );

Check error indicator

Checks if the error indicator associated with stream is set, returning a value different from zero if it is.
This indicator is generaly set by a previous operation on the stream that failed.
 
feof

function
int feof ( FILE * stream );

Check End-of-File indicator

Checks whether the End-of-File indicator associated with stream is set, returning a value different from zero if it is.
This indicator is generally set by a previous operation on the stream that reached the End-of-File.
Further operations on the stream once the End-of-File has been reached will fail until either rewindfseek or fsetpos is successfully called to set the position indicator to a new value.
 
stdin

object
FILE * stdin;

Standard input stream

The standard input stream is the default source of data for applications. It is usually directed to the input device of the standard console (generally, a keyboard).
stdin can be used as an argument for any function that expects an input stream as one of its parameters, like fgets or fscanf.
 
stdout

object
FILE * stdout;

Standard output stream

The standard output stream is the default destination of regular output for applications. It is usually directed to the output device of the standard console (generally, the screen).
stdout can be used as an argument for any function that expects an output stream as one of its parameters, like fputs or fprintf.
 
EOF

constant

End-of-File

It is a macro constant definition. It expands to a negative integral constant expression.
It is used as the value returned by several  functions to indicate failure, either because the End-of-File has been reached in a reading operation or because an error happened.
 
fopen

function
FILE * fopen ( const char * filename, const char * mode );

Open file

Opens the file whose name is specified in the parameter filename and associates it with a stream that can be identified in future operations by the FILE object whose pointer is returned. The operations that are allowed on the stream and how these are performed are defined by the mode parameter.
The running environment supports at least FOPEN_MAX files open simultaneously; FOPEN_MAX is a macro constant defined in .
ParametersfilenameC string containing the name of the file to be opened. This paramenter must follow the file name specifications of the running environment and can include a path if the system supports it.modeC string containing a file access modes. It can be:
"r"Open a file for reading. The file must exist.
"w"Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
"a"Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.
"r+"Open a file for update both reading and writing. The file must exist.
"w+"Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
"a+"Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseekrewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.
 
fclose

function
int fclose ( FILE * stream );

Close file

Closes the file associated with the stream and disassociates it.
All internal buffers associated with the stream are flushed: the content of any unwritten buffer is written and the content of any unread buffer is discarded.
Even if the call fails, the stream passed as parameter will no longer be associated with the file.
Parameters
streamPointer to a FILE object that specifies the stream to be closed.
Return ValueIf the stream is successfully closed, a zero value is returned.
On failure, EOF is returned.
 转自http://www.cnblogs.com/younes/archive/2010/01/04/1639173.html
if ($ != jQuery) { $ = jQuery.noConflict(); } var isLogined = false; var cb_blogId = 62725; var cb_entryId = 1639173; var cb_blogApp = "younes"; var cb_blogUserGuid = "59c04e1c-6acc-de11-ba8f-001cf0cd104b"; var cb_entryCreatedDate = '2010/1/4 20:50:00';
阅读(1904) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~