简体   繁体   English

scanf_s 读取字符我在做什么错?

[英]scanf_s reading characters what am i doing wrong?

{

    printf("Please give a random positive number for X: \n");
    scanf_s("%i", &X);
    char ch = getchar();
    char Gender;
    if (isdigit)
    {
        printf("Hay um... sorry what my i call you?");
        scanf_s("%i", Gender);

        printf("%lf \n" Gender ", if you may, please reread what i said, i asked you to give me a RANDOM NUMBER. \ncan you please explain to me why you gave me out of 1 through infinite numbers, a random letter? \n \n ");
    };

my problem is with ["%lf \n" Gender] saying that its expecting a [ ) ] can someone please explain what i am doing wrong?我的问题是 ["%lf \n" Gender] 说它期待 [ ) ] 有人可以解释我做错了什么吗?

A few issues here:这里有几个问题:

  1. scanf_s takes a pointer to where you want to store the read value, so it should be scanf_s("%i", &Gender); scanf_s需要一个指向您要存储读取值的位置的指针,因此它应该是scanf_s("%i", &Gender);
  2. In C, you can't just insert a char into a string.在 C 中,您不能只在字符串中插入一个char I'm not sure exactly what you want from this, since %lf is a really weird format for printing a char , but that's what I'm assuming you want.我不确定你到底想要什么,因为%lf是一种非常奇怪的打印char格式,但这就是我假设你想要的。 In that case, you would want to move Gender to the end: printf("%lf \n...letter? \n \n", Gender);在这种情况下,您可能希望将Gender移到末尾: printf("%lf \n...letter? \n \n", Gender); . . This will insert Gender in the position of %lf .这将在%lf的 position 中插入Gender

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM