code001

来源:互联网 发布:h3c 怎么修改端口23 编辑:程序博客网 时间:2024/06/16 13:08
#include <stdio.h>;
#include <stdlib.h>;
struct student_data {
    int  student_id;
    unsigned char marks[10];
};
size_t read_data( FILE *fp, struct student_data *p )
{
    return( fread( p, sizeof( struct student_data ), 1, fp ) );
}
int main( void )
{
    FILE *fp;
    struct student_data std;
    int i;
    fp = fopen( "/etc/fstab", "r" );
    if( fp != NULL ) {
        while( read_data( fp, &std ) != 0 ) {
            printf( "id=%d ", std.student_id );
            for( i = 0; i < 10; i++ ) {
                printf( "%3d ", std.marks[ i ] );
            }
            printf( "\n" );
        }
        fclose( fp );
        return EXIT_SUCCESS;
    }
    return EXIT_FAILURE;
}
原创粉丝点击