strcmp is not working in KDS

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

strcmp is not working in KDS

ソリューションへジャンプ
1,463件の閲覧回数
kayathrim
Contributor I

Hi all,

I am using KDS3.0 without Processor Expert and SDK in K22 family.

In this strcmp is not returning proper value even source destination strings are same.

What is the problem?

Regards,

Kayathri

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,200件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Hi Kayathri,

you have a few problems (or bugs, actually) in your code:

- you are using three large arrays (3x256 bytes) local to your function. If you have not allocated enough stack, this will be a problem.

- you are defining f_check[] twice.

- but the real problem is: strcmp() compares the strings up to a zero terminating byte. You don't have that as you initialize the buffers with a pattern, but you don't set the terminating character. I suggest you either fix that, or you are using strncmp() instead.

I hope this makes the problem clear and helps,

Erich

元の投稿で解決策を見る

0 件の賞賛
返信
3 返答(返信)
1,200件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Hi Kayathri,

can you provide an example of what you are doing?

And: have you included the header already, like with

#include <string.h>

?

I hope this helps,

Erich

0 件の賞賛
返信
1,200件の閲覧回数
kayathrim
Contributor I

Hi Erich,

i have included  <string.h>

below are my function

//strcmp test

char f_check[256];

char buf_data[256];

  int true1=0;

  int false1=0;

  int i = 5; //assigned simply to chech the strcmp return value

  char f_check[256];

  memset(f_check,0x41,sizeof(f_check));

  memset(buf_data,0x41,sizeof(buf_data));

// upto here i vaue is 5

  i = strcmp(f_check,buf_data);

// now i =5

  if(i==0)

  {

  true1++;

  }

  else

  {

control comes here

false1++;

  }

Regards,

Kayathri

0 件の賞賛
返信
1,201件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Hi Kayathri,

you have a few problems (or bugs, actually) in your code:

- you are using three large arrays (3x256 bytes) local to your function. If you have not allocated enough stack, this will be a problem.

- you are defining f_check[] twice.

- but the real problem is: strcmp() compares the strings up to a zero terminating byte. You don't have that as you initialize the buffers with a pattern, but you don't set the terminating character. I suggest you either fix that, or you are using strncmp() instead.

I hope this makes the problem clear and helps,

Erich

0 件の賞賛
返信