Tag: scanf

intptr_t和uintptr_t的字符串格式

intptr_t和uintptr_t的字符串格式是什么,它对32位和64位架构都有效。 编辑 warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type “AAA” 这是我在64位但不是32位的警告。 intptr_t AAA

C scanf(“%c”)的问题是逐个读取字符的function

以下代码在运行时会产生一个非常奇怪的结果。 #include #include int main(void) { for ( ; ; ) { char test; printf(“Please enter ‘w’ “); scanf(“%c”, &test); printf(“%c\n”, test); if (test == ‘w’) { printf(“Working\n”); } else { printf(“ERROR\n”); return 0; } } } 我想要发生的是每当我输入’w’时它继续循环,所以我可以再次输入’w’。 虽然我输入’w’,它的作用是转到else语句。 它似乎跳过了scanf()行。 我问过我认识的每个人谁知道C,但他们不知道如何解决它。 有人请帮帮我!

scanf和scanf_s之间的区别

所以我想问一下这两者有什么区别。如果有的话。在大学里,我接受过教学,我正在使用scanf,但在我的个人电脑上,视觉工作室不断发出警告。 error C4996: ‘scanf’: This function or variable may be unsafe. Consider using scanf_s instead. 我必须将所有scanf更改为scanf_s,否则程序将无法构建。 (我从2013年开始使用ms visual studio的最新版本)

什么时候我应该使用带有scanf(&)的&符号

使用scanf()在c中使用&符有什么规则? struct Student { char name[20]; int id; }; void main() { struct Student std1; printf(“enter name and id of std1\n”); scanf(“%s %d”, std1.name, &(std1.id)); } 为什么对于String我不需要使用&符号和int我必须使用它? 是否有关于何时使用&符号的规则?

如何scanf只有整数?

我希望代码运行直到用户输入整数值。 该代码适用于char和char数组。 我做了以下事情: #include int main() { int n; printf(“Please enter an integer: “); while(scanf(“%d”,&n) != 1) { printf(“Please enter an integer: “); while(getchar() != ‘\n’); } printf(“You entered: %d\n”,n); return 0; } 问题是如果用户输入浮点值, scanf将接受它。 Please enter an integer: abcd Please enter an integer: a Please enter an integer: 5.9 You entered: 5 怎么可以避免?

简单的C scanf不起作用?

如果我尝试以下内容: int anint; char achar; printf(“\nEnter any integer:”); scanf(“%d”, &anint); printf(“\nEnter any character:”); scanf(“%c”, &achar); printf(“\nHello\n”); printf(“\nThe integer entered is %d\n”, anint); printf(“\nThe char entered is %c\n”, achar); 它允许输入一个整数,然后完全跳过第二个scanf ,这真的很奇怪,因为当我交换两个(首先是char scanf)时,它工作正常。 究竟是什么错了?

在获取之前输入C. Scanf。 问题

我是C的新手,我在向程序输入数据时遇到了问题。 我的代码: #include #include #include int main(void) { int a; char b[20]; printf(“Input your ID: “); scanf(“%d”, &a); printf(“Input your name: “); gets(b); printf(“———“); printf(“Name: %s”, b); system(“pause”); return 0; } 它允许输入ID,但它只是跳过其余的输入。 如果我改变这样的顺序: printf(“Input your name: “); gets(b); printf(“Input your ID: “); scanf(“%d”, &a); 它会工作。 虽然,我不能改变秩序,我需要它原样。 有人能帮我吗 ? 也许我需要使用其他一些function。 谢谢!

c中的什么scanf函数返回?

我知道签名是 int scanf(const char *format, …) 这个int值与什么有关?

在%d之后使用带有空格的scanf(“%d”)

今天在我的c类中我遇到了scanf()命令,我们只是学习指针而且我们得到了一个问题,要求我们得到一个数组,然后在没有使用[]的情况下将其打印出来,除了声明(int)数组。 当然,这似乎是一块蛋糕,但不是你不小心写的时候: scanf(“%d”,arr + i); 您是否注意到%d后的空格? 当然确实花了我一段时间来弄明白但是由于某些原因导致循环变得疯狂,我希望你们帮助我(和我的老师)弄清楚为什么会这样。 例: #include #define LEN 10 void arrayInput(int * arr, unsigned int len); void arrayReverseOutput(int * arr, unsigned int len); int main(void) { int arr[LEN] = { 0 }; arrayInput(arr, LEN); arrayReverseOutput(arr, LEN); system(“pause”); return 0; } void arrayInput(int * arr, unsigned int len) { unsigned int i = […]

如果’&’没有放入’scanf’语句会怎么样?

我去了一个采访中,我被问到这个问题: 您对以下内容有何看法? int i; scanf (“%d”, i); printf (“i: %d\n”, i); 我回答了: 该程序将成功编译。 它会错误地打印数字,但它会一直运行到最后而不会崩溃 我做出的回应是错误的。 我不堪重负。 之后他们解雇了我: 在某些情况下,程序会崩溃并导致核心转储。 我不明白为什么程序会崩溃? 谁能解释一下原因? 任何帮助赞赏。