|
使用strcmp來(lái)比較兩個(gè)相同的字符數(shù)組時(shí),得不到相等的結(jié)果。根據(jù)程序運(yùn),table1和table2賦值相同的值,應(yīng)該相等才對(duì)啊,但我將if(strcmp(table1,table2)==0)變?yōu)閕f(strcmp(table1,table2)!=0)時(shí),蜂鳴器響了,也就是說(shuō)兩個(gè)數(shù)組不相等。請(qǐng)教下這是什么原因呢?難道不能這樣比較嗎?小弟新手,感謝指教。
代碼:
======================
#include <reg52.h>
#include <intrins.h>
#include <string.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit Beef=P0^1;
uchar code arrl[]={"123456"};
uchar table1[6],table2[6];
uchar a,s;
void delay(uint i) //延時(shí)函數(shù)
{while(i--);}
void Bee() //蜂鳴器函數(shù)
{
int x;
for(x=1000;x>0;x--)
{
Beef=~Beef;
delay(10);
}
}
void main()
{
for(a=0;a<6;a++)
{
table1[a]=arrl[a];
table2[a]=arrl[a];
}
if(strcmp(table1,table2)==0)
{
while(1)
{
Bee();
}
}
}
|
|