[英]What happens if I enter a character to a dynamically/statically allocated double array?
Right now I am using a dynamically allocated double array. 现在,我正在使用动态分配的双精度数组。 How can I check if someone has entered a character?
如何检查是否有人输入过角色?
double* scanarray(int length)
{
double* arr;
arr = (double*)malloc(sizeof(double)*length);
printf("Enter %d real numbers: \n", length);
for (int loop = 0; loop < length; loop++)
scanf_s("%lf", &arr[loop]);
return arr;
}
You could check return value of scanf
(and related functions such as scanf_s
): 您可以检查
scanf
返回值(以及诸如scanf_s
相关函数):
Return Value
返回值
Each of these functions returns the number of fields that are successfully converted and assigned;
这些函数中的每一个都返回成功转换和分配的字段数 。 the return value does not include fields that were read but not assigned.
返回值不包括已读取但未分配的字段。 A return value of 0 indicates that no fields were assigned.
返回值为0表示未分配任何字段。 The return value is EOF for an error or if the end of the string is reached before the first conversion.
如果发生错误或在第一次转换之前到达字符串的末尾,则返回值为EOF。
https://msdn.microsoft.com/en-us/library/t6z7bya3.aspx https://msdn.microsoft.com/zh-CN/library/t6z7bya3.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.