2012-08-20 06:14 AM
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?2012-08-20 06:38 AM
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.
2012-08-20 07:27 AM
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. Dan2012-08-20 07:30 AM
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. Dan2012-08-20 07:42 AM
Omit the ''volatile'', it is not necessary in this context.
Or cast it in your call via ''(char *)''.2012-08-20 07:54 AM
But in this case, strcat still does not work.
How could I use it to append a string? Thank you.2012-08-20 08:06 AM
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 ?2012-08-20 08:34 AM
#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
2012-08-20 08:35 AM
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.2012-08-20 08:47 AM
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=falseproblem2.bmp : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hza6&d=%2Fa%2F0X0000000bO9%2FR619LL39VlgOgZYsaSwotkPrnRZHV7jrP_1csEEI8Ko&asPdf=false