cancel
Showing results for 
Search instead for 
Did you mean: 

strcat method does not work

chai
Associate II
Posted on August 20, 2012 at 15:14

Hi,

When I use strcat to append a string to a destination string. It does not work. I did it like this.

char *item_list = '''';

strcat(item_list,''hello'');

When I set a break point and check the item_list, it is still NUll.

Any ideas?

24 REPLIES 24
frankmeyer9
Associate II
Posted on August 20, 2012 at 15:38

Check what your compiler actually generates for statements like

char *item_list = '''';

It is very likely an array of fixed size, probably even in code space, and not in RAM. I would try something like

volatile char item_list[SUFFICIENT_STR_SIZE] = '''';

to force it into RAM, and having an appropriate size.
chai
Associate II
Posted on August 20, 2012 at 16:27

Thank you for your information.

But when I change it, it gives me the error:

Error[Pe167]: argument of type ''char volatile *'' is incompatible with parameter of type ''char *''

Any ideas?

Thank you.

Dan

chai
Associate II
Posted on August 20, 2012 at 16:30

Thank you for your information.

But when I change it to

volatile char item_list[10]= '''';

strcat(&item_list,''hello'');

it gives me the error:

Error[Pe167]: argument of type ''char volatile (*)[10]'' is incompatible with parameter of type ''char *''

Then I changed it to

volatile char *item_list= '''';

strcat(item_list,''hello'');

it gives me error:

Error[Pe167]: argument of type ''char volatile *'' is incompatible with parameter of type ''char *''

Any ideas?

Thank you.

Dan

frankmeyer9
Associate II
Posted on August 20, 2012 at 16:42

Omit the ''volatile'', it is not necessary in this context.

Or cast it in your call via ''(char *)''.

chai
Associate II
Posted on August 20, 2012 at 16:54

But in this case, strcat still does not work.

How could I use it to append a string?

Thank you.

frankmeyer9
Associate II
Posted on August 20, 2012 at 17:06

Maybe it's time to get a little more specific.

What toolchain you are using, and which hardware ?

Have you debugged on assembler level to check what's actually happening ?

Posted on August 20, 2012 at 17:34

#include <
stdio.h
>
#include <
stdlib.h
>
#include <
string.h
>
void test(void)
{
char string[16];
strcpy(string, ''Hello '');
strcat(string, ''World!'');
puts(string);
}

Works for me
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chai
Associate II
Posted on August 20, 2012 at 17:35

I am using IRA Embedded Workbench IDE and using STM32L152L-Discovery board. I found that even I use following command:

char m[10] = '''';

for(int i=0; i<9; i++)m[i] = ‘o;

Then I look at m[i], it is still nothing in it.

Actually, I am new to this project, I don't know how to debug it on assembler level.

Thank you.

chai
Associate II
Posted on August 20, 2012 at 17:47

I just tried this code, and there is still nothing in string. And I looked through the assemble code. There are some very large numbers which seem wired. And I attached the assemble parts.

Thank you

________________

Attachments :

problem.bmp : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzUO&d=%2Fa%2F0X0000000bOA%2FBk_ttYeRHjqHOcCQtMhfF9uMeJZNPEJoGtFiFXlpGPQ&asPdf=false

problem2.bmp : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hza6&d=%2Fa%2F0X0000000bO9%2FR619LL39VlgOgZYsaSwotkPrnRZHV7jrP_1csEEI8Ko&asPdf=false