Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何到达文件中特定行的开头?_C - Fatal编程技术网

C 如何到达文件中特定行的开头?

C 如何到达文件中特定行的开头?,c,C,当我尝试使用fseek()返回到文件中某行的开头时,我得到一个错误 我的代码如下: fseek(inptr, -bi.biWidth * sizeof(RGBTRIPLE), SEEK_CUR) bi.biwidth的类型为int32\u t 我得到以下错误: runtime error: unsigned integer overflow: 18446744073709551613 * 3 cannot be represented in type 'unsigned long' 现在我明

当我尝试使用fseek()返回到文件中某行的开头时,我得到一个错误

我的代码如下:

fseek(inptr, -bi.biWidth * sizeof(RGBTRIPLE), SEEK_CUR)
bi.biwidth的类型为int32\u t

我得到以下错误:

runtime error: unsigned integer overflow: 18446744073709551613 * 3 cannot be represented in type 'unsigned long'
现在我明白了错误,但我不知道如何解决它。请帮忙

另外,还有什么方法可以实现这一点呢?

无符号数学

sizeof(RGBTRIPLE)
的值为3,类型为
size\u t
,一些是无符号类型。(
size\u t
在OP的机器上是
unsigned long

-bi.biWidth
的某些有符号类型的值为-3,比
size\u t
窄,很可能是
int

相乘时,-3将转换为
size\u t
类型,其值为
18446744073709551613u
0xfffffffffffd

此产品超过
尺寸\u t

fseek()
需要一个
long
,所以使用
long
数学

fseek(inptr, -bi.biWidth * (long) sizeof(RGBTRIPLE), SEEK_CUR)


RGBTRIPLE
的类型在此不存在问题

确保在表达式中使用有符号值。。。你永远不会得到负的、无符号的值。为什么位图宽度之前需要减号?@grochmal…但是
sizeof(RGBTRIPLE)
是无符号的,并且可能大于
int32\t
RGBTRIPLE
已经输入了uint8\t,并且
bi.biWidth*sizeof(RGBTRIPLE)
返回了一个无符号的长字符。因此
-(bi.biWidth*(int)(sizeof(RGBTRIPLE))
给了我正确的值。@Saha
sizeof
任何东西都给了
size\u t
值(无符号)。对
int
的强制转换确实解决了您的问题,但
RGBTRIPLE
是有符号类型还是无符号类型并不影响。