Program crashes when trying to read numbers with scanf

倖福魔咒の 提交于 2019-11-28 14:37:32

scanf takes the address of the variable in which it stores the input value. You need to change your scanf calls to

scanf("%d", &n1);
scanf("%d", &n2);
//          ^ note the & operator

Also, note that it's undefined behaviour to call fflush on an input stream. So, fflush(stdin) is not correct. You need to manually read and discard extraneous input left over in the stdin stream.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!