Combining strings in CodeWarrior for the MC68HC812

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Combining strings in CodeWarrior for the MC68HC812

3,339 次查看
tomrussell
Contributor I

Hi,

 

I'm a student doing a microprocessors segment on my degree at Coventry University and we've been given an assignment for the above processor (exact # is MC68HC812A4) - you'll have to bear with me a bit because this is the first time i've done anything along these lines :smileyhappy:

 

We're producing a simple program in C++ and as part of it i'd like to do some string operations

 

i.e.

 

char item1[3] = "0x0";

char item2[1] = "F";

char result;

 

strcat(result,item1);

strcat(result,item2);

 

Led_Port=result;

 

I've attempted to #include <string.h> at the top of the file, but when i go into the true-time debugger and attempt to run this code segment, the debugger halts at the strcat operation and the 'code' window says 'STRING.C NOT FOUND'.

 

Can anyone help? I'm probably making some kind of schoolboy error - or rather student error!

 

Thanks in advance.

标签 (1)
标记 (1)
0 项奖励
回复
5 回复数

1,438 次查看
CompilerGuru
NXP Employee
NXP Employee

It appers that the program is much more in C than in C++.

Check the sized of your arrays (result should be an array too, I guess this is a copy paste bug).

The arrays have to be large enough to contain a terminating 0 byte too, item1 and item2 are both too small.

If you do not change a variable, its good practise (and important on a small device) to make the variable const.

And if a variable only contains a const string, its less error prone not to define the size of the array.

E.g. static const char item1[] = "0x0";

 

Also make sure that the destination buffer is setup when you do the first strcat.

 

Daniel

0 项奖励
回复

1,438 次查看
bigmac
Specialist III

Hello,

 

Further to Daniel's comments, it would appear that the result variable should be defined as either an array or a pointer.

 

Regards,

Mac

 

0 项奖励
回复

1,438 次查看
tomrussell
Contributor I
Sorry - i should also add that this occurs whenever i try and use any 'str' operation - i'm not in the lab at the moment and the c++ code up there is probably far from correct and wouldn't compile :smileyhappy:
0 项奖励
回复

1,438 次查看
J2MEJediMaster
Specialist I

It sounds like you're not including the appropriate library that would contain the string handling functions. Did you use the New Project wizard to make the project?

 

---Tom

Message Edited by J2MEJediMaster on 2009-02-24 09:35 AM
0 项奖励
回复

1,438 次查看
tomrussell
Contributor I

Yeah, i did - created a C++ only project. CodeWarrior shows me having the following files in the filetree:

 

Sources

-main.cpp

-datapage.c (?)

Startup Code

-Start12.cpp

Libraries

-mc68hc812a4.h

-mc68hc812a4.c

-ansisi.lib

-cppsi.lib

 

I thought including the #include <string.h> in the header would import it from another filestore on compile though?

 

0 项奖励
回复