- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
每当我尝试运行此代码时,我都会遇到读取访问冲突:
#include<stdio.h>
#include<stdlib.h>
int i = 0;
struct basicValues{
float rate, hoursWorked, grossPay, basePay, overtimePay, taxesPaid, netPay;
char name[15];
};
void inputValues (struct basicValues *entered)
{
printf("Please enter your name, hourly pay, and hours worked this week: ");
scanf_s("%s %f %f", entered->name, entered->rate, entered->hoursWorked);
}
void main()
{
int i = 0;
struct basicValues workers[5];
for (i = 0; i < 5; ++i)
{
inputValues(&workers[i]);
printf("%c %f %f", workers[i].name, workers[i].rate, workers[i].hoursWorked);
system("pause");
}
}
我认为这与我的结构 inputValues 有关,但我不知道要更改什么。谢谢
最佳答案
您应该在原始值类型之前添加 &,因为 scanf 需要变量的地址。像这样
&entered->rate, &entered->hoursWorked
打印字符串时也使用 %s
,而不是 %c
关于c - 尝试将 scanf_s 写入 struct* 时读取访问冲突写入位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45131647/
一边回答this问题我在 Ideone 上编译了代码并得到这个错误 implicit declaration of function ‘scanf_s’ [-Wimplicit-function-de
我在编程方面相当新手,并且在一段代码上遇到了问题。我正在尝试输入一个单词,但是当我运行该程序并输入该单词时,它停止工作。 这是代码: int main(void){ char a[]=
这个问题已经有答案了: I am having trouble with multiple chars and scanf_s() [duplicate] (2 个回答) 已关闭 5 年前。 我编写了
{ printf("Please give a random positive number for X: \n"); scanf_s("%i", &X); char ch =
我试过这段代码,但它不起作用。 char word1[40]; printf("Enter text: \n"); scanf_s("%s", word1); printf("word1 = %s",
对于下面的代码(C 语言) int small_a, small_b; printf("Please input two numbers\n"); scanf_s("%d %d
如果我无法访问互联网,但知道我想使用 scanf_s() 函数从键盘获取输入 (stdin),我怎么知道在哪里声明缓冲区? 目前,当我进入 Visual Studio 中的 scanf_s() 函数时
我正在尝试制作一个程序,看看我可以用 C 中的结构做什么。但是在 scanf_s("%s", &user.name) 的主函数中出现错误: Exception thrown at 0x5C26D3EC
我在使用 scanf_s() 时遇到了一些问题;函数或开关函数,我第一次运行我的代码时它无法识别正确的字符并循环回到开头,但之后它工作正常。这是一个简单的计算器。 可能有一些简单的解决方案,因为我刚开
为什么在输入要放入结构的数字后到达第二个 scanf_s 时,以下代码会抛出异常。 这绝不代表一个完整的链表实现。 输入值后不确定如何进入下一个scanf_s?有什么想法吗? 编辑:使用建议的解决方案
char array1[10]; scanf_s("%9s", array1, (unsigned)_countof(array1); (unsigned)_countof(array1) 是什么意思
此代码崩溃: scanf_s("%c %d",&ch,&x);//Run error 但是这段代码有效: scanf_s("%c",&ch); scanf_s("%d",&x);//Run succe
程序: #include "stdafx.h" #include "stdio.h" #include "string.h" //#include "iostream" const int IDLEN
这是我的代码。这是学校作业。我必须编写一个程序来使用巴比伦人开发的方法等来计算数字的平方根,这不是重要的部分。我想知道是否可以忽略 scanf 中的字母,这样当我输入字母时,它就不会在我的终端中变得狂
所以我想在同一个scanf_s中写入两个变量。也许我什至没有使用正确的名称来描述我想要的东西,因为我对此很陌生,但基本上我希望它是这样的: What is your last and first na
这个问题已经有答案了: C programming - Loop until user inputs number scanf (4 个回答) 已关闭 5 年前。 编辑1:抱歉,我正在学习编程类(cl
我尝试使用 scanf_s 从用户那里获取日期和月份的输入(带有 visual studio 的编译器总是要求您使用 scanf_s,这就是我使用它的原因)。它允许我输入日期,但是当我输入月份(作为字
我正在对两个不同的输入使用 scanf_s 并将它们放入 char 数组中。我附上了代码和它给出的输出 char firstName[30]; char lastName[30]; int main(
我正在尝试编写一个简单的代码来输入 int 和 char 的值。 Visual Studio 抛出异常 #include int main() { int i; char c;
在大学学习编程的头几个月后,我一直在文件末尾或代码中的某些重要位置包含 scanf_s("%d");,在命令控制台在程序加载后不消失。 我似乎找不到关于以下方面的简明答案或解释: 如果我不写 scan
我是一名优秀的程序员,十分优秀!