我想从用户输入中获取矩阵值、行和列。所以我正在实现 do while
来做到这一点:
这仅适用于行:
do {
printf ("Inserisci il numero di righe ( intero-positivo-diverso da 0): ");
scanf ("%d",&righe);
} while (righe<=0);
我想检查用户是否只插入整数。我能做什么?
最佳答案
scanf
返回一个整数,指示它成功读取了多少“东西”。您可以在有条件的情况下对其进行测试,看看它是否满足您的需求。示例:
const int result = scanf ("%d",&righe);
if (1 != result) {
/* didn't get the 1 input we were looking for, do something about it! */
}
虽然您需要区分 EOF 和简单的整数。
关于c - 如何从用户c获取输入整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9537404/