比较字符串用户输入 [英] Comparing strings that user input
本文介绍了比较字符串用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我真的有问题的字符串。的如果的功能不会工作,这是从的其他的打印。为什么呢?
字符trenutni;
//更多code
的printf(Unesite波列koje zelite达otvorite \\ n!);
scanf函数(%C,&安培; trenutni);如果(trenutni =='A1'和;&放大器;!a1otvoreno = 0)
{
函数strncpy(A1,koordinate,sizeof的(A1));
的printf(A1 JE%S,A1);
的printf(李达zelite哒pogadjate Unesite言论报kolone,ZA konacno - [R伊犁阿古NE zelite upisite 0 \\ n吗?!);
scanf函数(%C,biranje);
brojodigranih ++;
a1otvoreno--;
如果(biranje =='A')
{
的printf(Unesite resenje ZA kolonu答:\\ n);
//更多code
其他
的printf(VEC STE otvorili到波列\\ n!);
解决方案
这看似可疑的:
trenutni =='A1'
通常情况下,你应该把单引号内的单个字符。
注意:依据标准:在包含多个字符(例如,'AB'
)的整型字符常量的值,[...]是实现定义的。
I really have problem with strings. If function wont work and it is printing from else. Why?
char trenutni;
//more code
printf("Unesite polje koje zelite da otvorite!\n");
scanf("%c",&trenutni);
if(trenutni=='a1' && a1otvoreno!=0)
{
strncpy(a1, "koordinate", sizeof(a1));
printf("A1 je %s", a1);
printf("Da li zelite da pogadjate? Unesite slovo kolone, za konacno R ili ako ne zelite upisite 0!\n");
scanf("%c",biranje);
brojodigranih++;
a1otvoreno--;
if(biranje=='A')
{
printf("Unesite resenje za kolonu A:\n");
//more code
else
printf("Vec ste otvorili to polje!\n");
解决方案
This seems suspicious:
trenutni=='a1'
Typically you should put a single character inside single quotes ''
.
NB: According to the standard: "The value of an integer character constant containing more than one character (e.g., 'ab'
), [...] is implementation-defined."
这篇关于比较字符串用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文