美文网首页
好奇怪,sacnf()出现问题

好奇怪,sacnf()出现问题

作者: Zdhj | 来源:发表于2017-03-11 23:15 被阅读12次

今天看《c语言入门经典》,照例打打代码练练手.

打了一段算术运算,居然无法运行。

代码如下。问题出现在“scanf()”那一行:

//program 2.8 calculations on a table

include <stdio.h>

int main(void){
float radius = 0.0f;//the raidus of the table
float diameter = 0.0f;//the diameter of the table
float circumference = 0.0f;//the circumference of the table
float area = 0.0f;//the area of the table
float pi = 3.14159265f;

printf("input the diameter of the table:");
scanf("%f", &diameter);//read the diameter from the keyboard

radius = diameter / 2.0f;//calculate the radius
circumference = 2.0f*pi*radius;//calculate the circumference
area = pi*radius*radius;//calculate the area

printf("\nthe circumference is %.2f", circumference);
printf("\nthe area is %.2f\n", area);
return 0;

}
————————————————————————————————————
20170320有新发现:
//program 3.1 a simple example of the if statement

include <stdio.h>

int main(){
int number = 0;
printf("\nenter an integer between 1 and 10: ");
scanf_s("%d", &number);

if (number > 5 )
    printf("you entered %d which is greater than 5 \n", number);
if (number < 6)
    printf("you entered %d which is less than 6 \n", number);
return 0;

}

问题的关键是把“ scanf ”改为“ scanf_s ”,IDE给出的原因是 scanf unsafe 。

具体为什么,有待解决。

相关文章

  • 好奇怪,sacnf()出现问题

    今天看《c语言入门经典》,照例打打代码练练手. 打了一段算术运算,居然无法运行。 代码如下。问题出现在“scanf...

  • 2018-04-18

    可怜之人,必有可悲之处。 生活出现问题,工作出现问题,感情出现问题,心情好烦躁,不知如何是好。

  • scanf函数

    一,使用目的在程序运行的时候,能让用户输入进而操作 二,特点阻塞线程,在sacnf函数完成之后,才能执行下面的代码...

  • python中random.shuffle的一个小坑

    random.shuffle会对np.array()产生很奇怪的反应,常常会出现问题,比如在tensorlow中传...

  • 关于最近的所学

    最近正在看关于C语言设计的书。对C语言有了一些认识。刚刚起步,只学习了几个语法。比如:printf,sacnf,s...

  • 12.23日课程总结

    出现问题我们要按照制度去执行,可以通过其他方式软措施慰问出现问题人,把握好方式和尺寸。

  • 2022-01-26

    明天还有一天就要放假,坚持好最后一天,检查好质量不要出现问题。

  • 2022-09-30

    维修完车辆要检查好,避免出现问题,客户不满意,加油

  • 1月3日精进

    今日体验:干完活一定要检查好免得客户把车取走后出现问题.不管与我们是否有关但是客户不会那么认为.所以要想不出现问题...

  • 开往春天的睡眠

    昨晚感觉小腿酸困,依照经验,应该是要发烧的节奏。好在脑门冰凉,没出现问题。童年关于发烧,留有奇怪的记忆,模糊而难以...

网友评论

      本文标题:好奇怪,sacnf()出现问题

      本文链接:https://www.haomeiwen.com/subject/lonogttx.html