Home > Back-end >  There are both Chinese characters and Numbers in the C language array, how to compare to the same ar
There are both Chinese characters and Numbers in the C language array, how to compare to the same ar

Time:10-12

Like a []={" 000000 zhang SAN "}
[b]={" 000000 zhang SAN ", "111111 li si"}
Why can't use a [0]==b [0] comparison like this

CodePudding user response:

With what method can compare arrays like this

CodePudding user response:

STRNCMP directly can compare Chinese characters is a composed of binary characters are multiple bytes, each byte is high 1 without conflict

CodePudding user response:

refer to the second floor u012538549 response:
STRNCMP directly can compare Chinese characters is a Chinese characters composed of binary multiple bytes, each byte is high 1 without conflict

I use this method to compare, completely can't find the same elements, the count has been to 0, the following code
For (j=0; j<160; J++)
{

The fgets (StrLine2 [j], 1024, fp2);//read a line of
Count=0;
for(i=0; i<110; I++)
{
The fgets (StrLine1 [I], 1024, fp1);
If (STRNCMP (StrLine2 [j], StrLine1 [I], 3)==0)
count++;
}
This is the reason why

CodePudding user response:

reference Lgoloria reply: 3/f
Quote: refer to the second floor u012538549 response:
STRNCMP directly can compare Chinese characters is a Chinese characters composed of binary multiple bytes, each high byte is 1 without conflict

I use this method to compare, completely can't find the same elements, the count has been to 0, the following code
for(j=0; j<160; J++)
{

The fgets (StrLine2 [j], 1024, fp2);//read a line of
Count=0;
for(i=0; i<110; I++)
{
The fgets (StrLine1 [I], 1024, fp1);
If (STRNCMP (StrLine2 [j], StrLine1 [I], 3)==0)
count++;
}
This is the reason why
fp1 need to reset the

CodePudding user response:

Use STRCMP STRNCMP/memcmp can compare?

Call these function is also a character in a character,

CodePudding user response:

reference 4 floor lin5161678 response:
Quote: reference Lgoloria reply: 3/f

Quote: refer to the second floor u012538549 response:
STRNCMP directly can compare Chinese characters is a Chinese characters composed of binary multiple bytes, each high byte is 1 without conflict

I use this method to compare, completely can't find the same elements, the count has been to 0, the following code
for(j=0; j<160; J++)
{

The fgets (StrLine2 [j], 1024, fp2);//read a line of
Count=0;
for(i=0; i<110; I++)
{
The fgets (StrLine1 [I], 1024, fp1);
If (STRNCMP (StrLine2 [j], StrLine1 [I], 3)==0)
count++;
}
This is the reason why
fp1 need to reset the

Followed rewind (fp1) didn't effect...

CodePudding user response:

Char * p="don't understand what you want to compare";
Char p2 []="don't understand what you want to compare";
Size_t len=p1_len=strlen (p1);
STRNCMP (p1, p2, p1_len)==0;
So just you write the cycle of wool
  • Related