所以我目前正在学习C编程,为大学期开学做准备.有点像"抬腿"的事情.无论如何,我正在做一些比较字符串和使用字符串复制函数在字符串数组中放置新值的练习,但我得到一些我真的无法解释的意外行为.无论我输入什么,它总是显示字符串比较检查的肯定结果,我无法确定我出错的地方.如果有人愿意帮助我,我将不胜感激!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char tVar1[10];
char tVar2[10];
printf("Enter your first test variable: \n");
scanf("%c", &tVar1);
strcpy(tVar2, "yes");
if(strcmp(tVar1, "yes") == 0)
{
printf("It would probably be more effective if you used two different variables.");
}
else
{
printf("Nope, just the same amount of effectiveness.");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)