Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以让程序读取';吗';如果用户放入''?使用C_C_Scanf - Fatal编程技术网

我可以让程序读取';吗';如果用户放入''?使用C

我可以让程序读取';吗';如果用户放入''?使用C,c,scanf,C,Scanf,我有一个代码,用户必须把每升油漆的价格。。。但它只接受“2.50”这样的价格,如果用户输入“2.50”,我能让程序将逗号转换成点吗?使用C printf ("\n How many liters of green paint we'll use? "); scanf ("%d", &green); printf ("\n How many liters of blue paint we'll use? "); scanf (" %d", &blue

我有一个代码,用户必须把每升油漆的价格。。。但它只接受“2.50”这样的价格,如果用户输入“2.50”,我能让程序将逗号转换成点吗?使用C

    printf ("\n How many liters of green paint we'll use? ");
    scanf ("%d", &green);
    printf ("\n How many liters of blue paint we'll use? ");
    scanf (" %d", &blue);
    printf ("\n What's the price for the liter of green paint? ");
    scanf ("%f", &priceG);
    fflush(stdin);
    printf ("\n What's the price for the liter of blue paint? ");
    scanf ("%f", &priceB);

将输入收集到字符串中并执行操作

遍历字符串的每个字符,如果遇到
将其替换为

在遍历时将遍历的字符放入另一个字符串中,当发现
时,将其替换为


此过程可能会很长,但可能会有帮助并满足您的要求。

您可以使用
setlocale(LC\u NUMERIC,“yourlocate”)
\include
为小数点设置所需的区域设置。()


yourLocale
必须是计算机上可用的有效区域设置字符串,并使用
作为小数点,例如
de\u de
。您可以使用
locale-a

获得可用的语言环境,您必须更改您的语言环境。请参阅,例如,您是否可以添加整个过程中所需的必要类型转换procedure@t3n:遍历一个字符串并将其放入另一个字符串不需要任何转换。。完成此操作后,您可以使用atof将字符串转换为浮点….“完成此操作后,您可以使用atof将字符串转换为浮点…”。。。。我在找这样的东西……thanx来澄清……)