当输入 0 时如何使我的 while scanf 循环终止?

How can I make my while scanf loop terminate when 0 is entered?

如何在输入 0(前后都有 space)时终止以下循环?现在我需要手动输入 '\n' 来结束循环。

while (scanf("%hd", &array[length++]) == 1)

扫描到临时

short shorttmp;
while (scanf("%hd", &shorttmp) == 1) {
    if (shorttmp == 0) break;
    array[length++] = shorttmp;
    // ...
}