c - 我的第二个 scanf 不起作用 - 我该怎么办?

标签 c scanf clion

我的第二个 scanf在此代码中不起作用,计算机不会等待我输入第二个值。

我知道什么时候会发生 %c只需要在 % 之前放一个空格
但不能让它与 %f 一起工作

#include <stdlib.h>
#include <stdio.h>

main()
{
    float a, p;
    printf("Insira seu peso: "); scanf("%.1f", &p);
    printf("Insira sua altura: "); scanf("%.2f", &a);
}

最佳答案

.不是 scanf() 中的有效格式标志字符函数族。格式与 printf() 相关格式家族(这不是偶然的),但它们远非相同。

Each conversion specification is introduced by the character '%' … after which the following appear in sequence:

  • An optional assignment-suppressing character '*'.

  • An optional non-zero decimal integer that specifies the maximum field width.

  • [CX] ⌦ An optional assignment-allocation character 'm'. ⌫

  • An option length modifier that specifies the size of the receiving object.

  • A conversion specifier character that specifies the type of conversion to be applied. The valid conversion specifiers are described below.


没有提及 .在那里。

关于c - 我的第二个 scanf 不起作用 - 我该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60255319/

相关文章:

c - Eclipse/MinGW 中的 scanf 问题

c - Labjack 湿度探头示例

c++ - 检查字符串是否以 (%i) 结尾,然后将该数字分配给变量

c++ - 在 Mingw-w64 中使用 %I64u 得到奇怪的结果

c++ - CLion (C++) - 无匹配函数

c++ - 在 Intellij 的 CLion 结构面板中显示类名

C++11 错误不匹配调用 main 之外的 Ifstream

python - 使用 CFFI 的缓冲协议(protocol)

c - 在c中获取除第一个argv数组之外的所有数组拼接

C - 模 (%),如何计算 IntToString 转换的值,其中 num/= 10