This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

String Initialisation Issue

Other Parts Discussed in Thread: CONTROLSUITE, MAX232

Hi,
I have got an issue with one of the example programs from the controlSUITE package:
Example_2806xSci_Echoback

It is a fairly simple Hello World program, although it seems to have an issue with the string assignments.

here the relevant code:
void main(void)
{
char *msg;
msg="\r\n\nHello World!\0";
scia_msg(msg);
}

In theory quite simple, although for some reason the msg-pointer points to an uninitialized memory-block or some block used by something else since it contains invalid characters as well as some other totally unrelated text, altough it allways seems to be exacly the same values after restart.

I also tried using:

char msg[50]; or char *msg;
strcpy(msg, "My TestString");

char msg[50]; or char *msg;
msg[0]='M';
msg[1]='y';
.....

Where only the last 2 worked, the strcpy() did not seem to produce anything useful eighter.
Now even though it would in theory be possible i can not quite beleeve that i am supposed to define every string char-by-char :)

What did work:
reading characters from RS232-controller (MAX232)
sending strings (once they were properly initialized) via RS232

Used Tools:
CCS v5.2.1.00018
controlSUITE v3.0.3
TMX320F28069 with DockingStation

It would be much appreciated if someone could help.
Br,
Chris

  • The idiom you want is

    const char msg[] = "My TestString";

    or just pass the string constant directly to scia_msg

    scia_msg("My TestString");

    In the following code fragment, msg is not initialized, so it is an invalid pointer; writing through it will probably scribble on random memory.

    char *msg;
    strcpy(msg, "My TestString");

    You would typically allocate memory for it

    char *msg = malloc(strlen("My TestString") + 1);
    strcpy(msg, "My TestString");
  • Thank you for your quick reply but it seems like it had nothing to do with the source code,
    i previously had CCS v4.1 installed and created a config file for 2809 which seemed to be the device i am using since the 5 digit versions did not show up,
    this file was accidently loaded into the new installation of CCS5 and seems to have caused an addressing issue,
    deleting the old configuration file fixed the problem, now the code is working fine in its original form.

    Although i appreciate your input since i will definately need the memalloc function sometime soon.

    Br,
    Chris