[英]: 0xC0000005: Access violation writing location 0x00000000 C++ with inline assembly
[英]C++: 0xC0000005: Access violation writing location 0x00000000
我想知道我的程序是否可以得到一些帮助。 如标题中所述,我的程序遇到访问冲突。 我意识到这与取消引用垃圾指针有关,我很确定自己已经缩小了它的界限,我只是不确定为什么它实际上在破裂,以及如何解决它。 代码如下:
void determineInputType(char input[kMaxUserInput])
{
char* flag = NULL;
if (*(flag = strchr(input, '.')) != NULL)
{
double grade = 0;
if ((sscanf(input, "%lf", grade)) == 1) // problem is on this line
{
//rest of the code continues here
我如何获得输入的是这里:
void getUserInput(char* userInput)
{
printf("Enter a student's grade: ");
fgets(userInput, kMaxUserInput, stdin);
clearCRLF(userInput);
}
最后是主要的:
int main(void)
{
char userInput[kMaxUserInput] = { 0 };
getUserInput(userInput);
determineInputType(userInput);
return 0;
}
对此的任何帮助将不胜感激,因为它困扰了我一段时间。 非常感谢您抽出宝贵的时间,如果还有其他需要发布的信息,请告诉我。
scanf
系列要求您提供一个指向要填充的值的指针 :
if ((sscanf(input, "%lf", &grade)) == 1) // problem is no longer on this line
你有它的方式,可以设置grade
为零,那么使用它作为指针。
标准的相关部分(C ++ 11 7.19.6.2 /12
C99)为7.19.6.2 /12
(我的粗体):
a,e,f,g
匹配一个可选的带符号浮点数,无穷大或NaN
,其格式与strtod
函数的主题序列所期望的格式相同。 相应的参数应为指向浮动的指针。
l
(ell)-指定...后面的a
,A
,e
,E
,f
,F
,g
或G
转换说明符适用于类型指针为double的参数; ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.