本文介绍了如何在C中比较字符数组的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



谁能告诉我如何比较char数组的值?

我的代码示例:

Hi,

Can anyone tell me that how can I compare a value of char array?

My code sample:

typedef struct
{
  char pDocId[14 + 1];
} sBlocRepSRR;

typedef struct
{
  sBlocRepSRR pBlocRepSRR[MAX_REPONSES + 1];
}sRepSRR;

void func(sRepSRR * pResponse)
{
 for (i=0; i<icount; i++)
 {
   if (pResponse->pBlocRepSRR[k].pDocId_PDF < pResponse->pBlocRepSRR[j].pDocId_PDF)
   {    
        printf("k is less than j\n");
        k = j;        
   } else {   
        printf("k is greater than j\n");
        k = k;       
   }
 }
 printf("Maximum value is %s\n", pResponse->pBlocRepSRR[k].pDocId_PDF);
}



其中pResponse-> pBlocRepSRR [k] .pDocId_PDF的值为"020000001110"/"025000000556"/"02500000204"等...

请帮我从字符数组中获取最大价值.
在此先感谢.



where values of pResponse->pBlocRepSRR[k].pDocId_PDF are "020000001110" / "025000000556" / "02500000204" etc...

Please help me out for getting maximum value from character array.
Thanks in advance.

推荐答案

int strcmp(const char *string1, const char *string2);




返回的值可能是:




The returned value could be:


    • <如果string1小于string2

    • < 0 if string1 is less than string2
  • = 0 如果string1等于string2
  • = 0 if string1 is equal to string2
  • >如果string1大于string2


Poonamol写道:
Poonamol wrote:

if(pResponse-> pBlocRepSRR [k] .pDocId_PDF < pResponse-> pBlocRepSRR [j] .pDocId_PDF)

if (pResponse->pBlocRepSRR[k].pDocId_PDF < pResponse->pBlocRepSRR[j].pDocId_PDF)



更改为:



Change to:

long lk, lj;
lk = atol(pResponse->pBlocRepSRR[k].pDocId_PDF);
lj = atol(pResponse->pBlocRepSRR[j].pDocId_PDF);
if ( lk < lj )



:)



:)



这篇关于如何在C中比较字符数组的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 19:56