- 论坛徽章:
- 0
|
typedef struct
{
int sid;
char *name;
int chinesegrade;
int mathgrade;
struct student *np;
}student;
void readdatafile()
{
printf( "place enter datafilename:" );
char *fname = malloc( 128 );
scanf( "%127s",fname );
printf( "%s\n",fname );
if( access( fname,F_OK|R_OK )==0 )
{
FILE *fp = fopen( fname,"r" );
student *tmp = malloc( sizeof( student ) );
tmp->name=malloc( 8 );
vfscanf( fp,"%d\t%s\t%d\t%d\n",&( tmp->sid ),tmp->name,&( tmp->chinesegrade ),&( tmp->mathgrade ) );
fclose(fp);
}
else
printf( "not exits or not read\n" );
}
|
这是读入的文件内容
0 asdf 4 4
1 dxd 5 5
2 fj 6 6
分割符号均为\t
[ 本帖最后由 houtinghua 于 2009-3-16 14:07 编辑 ] |
|