请原谅我的任何错误(这是我的第一次).谢谢!
#include<stdio.h>#include<conio.h>main (){ int num1,num2,result; char oper; scanf_s("%d%c%d",&num1,&oper,&num2); switch(oper) { case '+': result = num1 + num2; printf("%d",result); break; case '-': result = num1 - num2; printf("%d",result); break; case '*': result = num1 * num2; printf("%d",result); break; case '/': result = num1 / num2; printf("%d",result); break; default: printf("ERROR: INVALID OR UNRECOGNISED input\n"); break; } _getch();}解决方法 使用
scanf_s
时,对于%c格式字符串,您必须指定要读取的字符数: scanf_s("%d%c%d",1,&num2);
documentation描述了要求:
总结Unlike scanf and wscanf,scanf_s and wscanf_s require the buffer size to be specifIEd for all input parameters of type c,C,s,S,or string control sets that are enclosed in []. The buffer size in characters is passed as an additional parameter immediately following the pointer to the buffer or variable.
以上是内存溢出为你收集整理的访问冲突错误C.全部内容,希望文章能够帮你解决访问冲突错误C.所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)