|
发表于 2004-2-12 17:07:56
|
显示全部楼层
fgets()的例子
- #include <stdio.h>
- #include <stdlib.h>
- void process_record( char *buf )
- {
- printf( "%s\n", buf );
- }
- int main( void )
- {
- FILE *fp;
- char buffer[100];
- fp = fopen( "file", "r" );
- fgets( buffer, sizeof( buffer ), fp );
- while( ! feof( fp ) ) {
- process_record( buffer );
- fgets( buffer, sizeof( buffer ), fp );
- }
- fclose( fp );
- return EXIT_SUCCESS;
- }
复制代码
putc()的例子
- #include <stdio.h>
- #include <stdlib.h>
- int main( void )
- {
- FILE* fp;
- int c;
- fp = fopen( "file", "r" );
- if( fp != NULL ) {
- while( (c = fgetc( fp )) != EOF ) {
- putc( c, stdout );
- }
- fclose( fp );
- }
- return EXIT_SUCCESS;
- }
复制代码 |
|