【发布时间】:2016-12-21 16:53:41
【问题描述】:
这是我的程序:
#include <stdio.h>
#include <string.h>
int main(){
char alegere[10];
int a;
printf ("Alege natura matricei tale: (Numere/Caractere)");
scanf ("%s", &alegere[10]);
if (strcmp(alegere, "Numere") == 0){
printf("a");
} else
printf ("b");
return 0;
}
它应该将我从键盘输入的字符串与字符串“Numere”进行比较,但如果我输入字符串“Numere”或任何其他字符串,结果将是相同的,我将打印“b” ...那我做错了什么?
【问题讨论】:
-
@user3121023 我得到了同样的结果
-
这段代码编译正确吗?字符串比较应该是 (strcmp(alegere, "Numere") == 0)..
-
#include <string.h> -
@WeatherVane 我有,只是忘了在这里输入。
-
还有什么你忘记的吗,比如
)?请发布显示问题的Minimal, Complete, and Verifiable example。 “可验证”是指您,因此我们不会回答虚构的问题。