Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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_String - Fatal编程技术网

C 向用户询问字符串问题

C 向用户询问字符串问题,c,string,C,String,我试图使用fgets()从用户那里获取字符串,但每当我运行程序时,它都会跳过fgets(),这意味着它不允许我输入任何内容 printf("*********************************\n"); printf(" Stock 3\n"); printf("*********************************\n"); printf("

我试图使用fgets()从用户那里获取字符串,但每当我运行程序时,它都会跳过fgets(),这意味着它不允许我输入任何内容

    printf("*********************************\n");
    printf("             Stock 3\n");
    printf("*********************************\n");

    printf("Enter stock name: ");
    fgets(name,10,stdin);
    printf("Enter the number of shares: ");
    scanf("%d", &share3);
    printf("Enter the buy price, current price, and fees: ");
    scanf("%f, %f, %f", &buy_p3, &current_p3, &fees3);

    puts("");

我相信这与跳过它有关,但我不确定它是从哪里来的。谢谢你的帮助。谢谢

尝试在FGET之前放置虚拟扫描。例如,scanf(“%s”、&s)。这将解决换行问题。最简单的方法是使用
scanf(“%9s”)
读取股票名称!否则,您可以使用一个简单的
scanf(“”
尝试在fgets之前放置一个虚拟scanf来使用所有空格,包括行初始空格。例如,scanf(“%s”、&s)。这将解决换行问题。最简单的方法是使用
scanf(“%9s”)
读取股票名称!否则,您可以使用一个简单的
scanf(“”)