簡體   English   中英

C - 在Visual Studio 2012中使用scanf_s打印錯誤

[英]C - Error print char with scanf_s in Visual Studio 2012

首先,我的代碼:

#include <stdio.h>

int main(){
   int a;
   char b;

   printf("Insert number: ");
   scanf_s("%i",&a);
   getchar();

   printf("Insert character: ");
   scanf_s("%c",&b);

   printf("Number: %i\n",a);
   printf("Character: %c\n",b);

   getchar();
   getchar();
   return 0;
}

我使用scanf_s但是visual studio 2012用scanf說錯誤。 好吧,int沒有問題,但問題是我可以使用char。

保存在var中的char但是當我調用printf這個var時,不顯示任何內容,為什么?

我在linux上檢查這個並且工作得很好。

對不起我的英文:)

您必須在scanf_s中指定輸入字符串或字符的大小

更改

scanf_s("%c",&b);

scanf_s("%c", &b, 1);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM