当前位置: 技术问答>linux和unix
请问如何给fpos_t赋值??
来源: 互联网 发布时间:2016-02-19
本文导语: 我在学习linux下的C编程,在msdn上看见如下代码: /* FGETPOS.C: This program opens a file and reads * bytes at several different locations. * * Place this code in a file called FGETPOS.C and then * put the file in your project dir...
我在学习linux下的C编程,在msdn上看见如下代码:
/* FGETPOS.C: This program opens a file and reads
* bytes at several different locations.
*
* Place this code in a file called FGETPOS.C and then
* put the file in your project directory.
*/
#include
void main( void )
{
FILE *stream;
fpos_t pos;
char buffer[20];
if( (stream = fopen( "fgetpos.c", "rb" )) == NULL )
printf( "Trouble opening filen" );
else
{
/* Read some data and then check the position. */
fread( buffer, sizeof( char ), 10, stream );
if( fgetpos( stream, &pos ) != 0 )
printf( "fgetpos error" );
else
{
fread( buffer, sizeof( char ), 10, stream );
printf( "10 bytes at byte %I64d: %.10sn", pos, buffer );
}
/* Set a new position and read more data */
pos = 140;
if( fsetpos( stream, &pos ) != 0 )
printf( "fsetpos error" );
fread( buffer, sizeof( char ), 10, stream );
printf( "10 bytes at byte %I64d: %.10sn", pos, buffer );
fclose( stream );
}
}
在编译时,系统报错如下:
fgetpos.c: In function `main':
fgetpos.c:31: error: incompatible types in assignment
请问是什么原因?为什么给fpos_t赋值时会报错呢??我用的是64位的机器。还请各位大侠帮帮忙。
/* FGETPOS.C: This program opens a file and reads
* bytes at several different locations.
*
* Place this code in a file called FGETPOS.C and then
* put the file in your project directory.
*/
#include
void main( void )
{
FILE *stream;
fpos_t pos;
char buffer[20];
if( (stream = fopen( "fgetpos.c", "rb" )) == NULL )
printf( "Trouble opening filen" );
else
{
/* Read some data and then check the position. */
fread( buffer, sizeof( char ), 10, stream );
if( fgetpos( stream, &pos ) != 0 )
printf( "fgetpos error" );
else
{
fread( buffer, sizeof( char ), 10, stream );
printf( "10 bytes at byte %I64d: %.10sn", pos, buffer );
}
/* Set a new position and read more data */
pos = 140;
if( fsetpos( stream, &pos ) != 0 )
printf( "fsetpos error" );
fread( buffer, sizeof( char ), 10, stream );
printf( "10 bytes at byte %I64d: %.10sn", pos, buffer );
fclose( stream );
}
}
在编译时,系统报错如下:
fgetpos.c: In function `main':
fgetpos.c:31: error: incompatible types in assignment
请问是什么原因?为什么给fpos_t赋值时会报错呢??我用的是64位的机器。还请各位大侠帮帮忙。
|
不能给它赋值,它是个结构体,你所能对它的操作就是:保存当前的位置值,以后再回到这个位置.不支持随意设置位置.
你可以这样给它赋值
pos.__pos=140.
但是对于这样的赋值在有些系统内产生的效果是没有定义的.
你可以这样给它赋值
pos.__pos=140.
但是对于这样的赋值在有些系统内产生的效果是没有定义的.