I need to take 2 char strings (6 character date) (and (8 charachter operatror id) convert to uin32 to send over a bus to store by another processor. That processor later sends them back as uint32 and I need to conver back to char strings.

Two files need access to these 2 so I declare & initialize in one c file then declare extern in the other. The taIn and taOut are arrays of 32 bit words. and my code is

[taMsgOut->data[6]  =  (Uint32)Test_Date;      
  taMsgOut->data[7]  =  (Uint32)Operator_ID; 
       
  Test_Date[0]           = (char)taMsgIn->data[6];      
  Operator_ID[0]         = (char)taMsgIn->data[7]; ]

Not really sure what your question is...

>>I need to take 2 char strings (6 character date) (and (8 charachter operatror id) convert to uin32

Are you talking about converting from ansi to unicode strings? e.g. from char* to wchar_t* ? Here is a 4-year-old thread, but still relevant.

Storing a string as an integer (array element) does not work here

taMsgOut->data[6] = (Uint32)Test_Date;

for 2 reasons (a) casting a string pointer to an int will transmit the pointer, but not the actual string (that the pointer points toward), resulting in garbage, or worse.
(b) the 4-byte integer does not have space for the 6-byte string, even if the code was changed.

The characters can be packed tighter, but the easiest way is to use a longer taMsgOut, and use one 32-bit array element per character, with a loop at both ends

for (int i = 0; i < 5; i++) {
  taMsgOut.data[6+i] = testDate[i];
}

Thanks man, I'll try this ! I'll post what happens.

Joe

Thanks man, I'll try this ! I'll post what happens.

Joe

You are right as the way I wsa doing this yielded garbage.

#define TEST_DATE_SIZE = 7 
char   Test_Date       [TEST_DATE_SIZE]        = {0x30};

taMsgOut is an array of 32 Uint32 words

OK I tried

for (i = 0; i < 5; i++)
        {
          taMsgOut->data[9+i] = Test_Date[i];  
        }
a

nd

for (i = 0; i < 5; i++)
        {
          taMsgOut->data[9+i] = (Uint32)Test_Date[i];  
        }

the compile fails "error: expression must have pointer-to-object type" in both cases.

but

for (i = 0; i < 5; i++)
        {
          taMsgOut->data[9+i] = (Uint32)Test_Date;  
        }

Compiles but I doubt would work as there is no indexing into Test_Date.

Any thoughts/help greatly appreciated !

Thank you,

Joe

Can you post how you have declared taMsgOut ?

Sure it is

TaMsgType taMsgOut

typedef struct
{
  UINT16 msgId;
  UINT16 wordCount;
  UINT32 data[MAX_MESSAGE_DATA_SIZE];
} TaMsgTyp;

Where
#define MAX_MESSAGE_DATA_SIZE 37

Thank you for the help !

Joe

Should you not be using the dot(.) operator instead of the member by pointer (->) operator to access the member data ?
taMsgOut is an object not a pointer to object

Yes you're right so I changed to

    for (i = 0; i < 5; i++)
    {
      taMsgOut.data[9+i] = (Uint32)Test_Date[i];  
    }

and now compiler gets 2 errors

error: expression must have struct or union type
error: expression must have pointer-to-object type

I haven't written code in 9 yrs and am at a loss. I appreciate all of your help !

Joe

Please post enough of the code that I can run the compiler on it.

Sure it is

TaMsgType taMsgOut

typedef struct
{
UINT16 msgId;
UINT16 wordCount;
UINT32 data[MAX_MESSAGE_DATA_SIZE];
} TaMsgTyp;


Joe

In the code that you have posted, you have made the object of the struct before you have define the struct itself. This is a compile time error.

UncleLeroy,

I think this is enough.

Thank you,
Joe

#define TEST_DATE_SIZE = 7 
char Test_Date [TEST_DATE_SIZE] = {0x30}; 

static MsgTyp TaOut;

#define MAX_MESSAGE_DATA_SIZE 37

typedef struct
{
UINT16 msgId;
UINT16 wordCount;
UINT32 data[MAX_MESSAGE_DATA_SIZE];
}MsgTyp;

MsgTyp* taMsgOut  = ta_msg_out();

//---------------------------------------------------------------------------
//
// Function Name  : ta_msg_out
//
// Description    : This function returns a pointer to the one copy of
//                  the TA output buffer.
//---------------------------------------------------------------------------
MsgTyp* ta_msg_out()
{
    return &TaOut;
}



for (i = 0; i < 5; i++)
{
taMsgOut->data[9+i] = (Uint32)Test_Date[i]; 
}

abhimanipal,

I got an email you posted but don't see it.

Thank you,
Joe

Its above the post in which you pasted code
PS: Why are post numbers removed from the new interface ?/Or is there a way to enable it ?

Guys in the code I pasted above I copy/pasted the wrong thing. Please replace

for (i = 0; i < 5; i++)
{
taMsgOut->data[9+i] = (Uint32)Test_Date[i]; 
}

with

for (i = 0; i < 5; i++)
        {
          taMsgOut.data[9+i] = (Uint32)Test_Date[i];  
        }

The idea was for you to send code that was ALREADY compilable,
your code had syntax errors:
define does not use "=", function was used before declared, no main(),
mis-spelled "Uint32" (v.s. UINT32).
And your previous answer about how msgOut was declared was misleading,
you should have said it was declared as a global object, with another pointer variable which points to it. Note that the pointer is redundant, since the code has full access to the global object.

Your post should also be inside the "code" brackets (use the # on the menu),
and all code needs comments.

Once I corrected the trivial errors, it compiled with no problem.

#define TEST_DATE_SIZE 7
char Test_Date[TEST_DATE_SIZE] = {0x30}; 

#define MAX_MESSAGE_DATA_SIZE 37

#define UINT16 unsigned short
#define UINT32 unsigned int

typedef struct
{
  UINT16 msgId;
  UINT16 wordCount;
  UINT32 data[MAX_MESSAGE_DATA_SIZE];
} MsgTyp;

static MsgTyp TaOut;

//---------------------------------------------------------------------------
//
// Function Name : ta_msg_out
//
// Description : This function returns a pointer to the one copy of
// the TA output buffer.
//---------------------------------------------------------------------------
MsgTyp* ta_msg_out()
{
  return &TaOut;
}

int main() {
  int i;
  MsgTyp* taMsgOut;
  taMsgOut = ta_msg_out();

  for (i = 0; i < 5; i++)
  {
    taMsgOut->data[9+i] = (UINT32)Test_Date[i]; // 9..14
  } 
}

Sorry for my misunderstanding and thank you very much for all of your help and attention.

I still get a compile error "error: expression must have pointer-to-object type" with my compiler. I am new on my program and use TI Code Composer 3.1 which isn't even supported by TI anymore. I should be able to take it from here.

Thank you all,

Joe

Doesn't your crappy compiler tell you which line has the error?

I turned on all of the "extra warning" options in both the gcc and g++ compilers, no errors or warnings. Are you sure you compiled the same code that I posted?

UncleLeroy,
The line that is flagged is below.
"error: expression must have pointer-to-object type"

Thank you,

Joe

taMsgOut->data[9+i] = (UINT32)Test_Date[i]; // 9..14

Are you still getting the error ?
I compiled it on the compiler that I have and it compiled just fine .....
Maybe you want to try a new complier

Please confirm, did you save and compile the exact code that I sent (all of it, top to bottom)? Did you compile it as-is, or did you rearrange it?

Yes my code is the same but I still get the error. I have some other code that is almost identicle in another file (definitions etc. that sends instead of receives and it compiles fine. My SW lead returns from vacation tomorrow...I will ask him and let you know.

Thanks again,

Joe

for (i = 0; i < 5; i++)
        {
          Test_Date[i]  = taMsgIn->data[9+i];  // 9..14
        }

There was an error in your reply "I cut/pasted the wrong code". The old version with taMsgOut->data[] correctly used pointer->syntax and the new version with taMsgOut.data[] incorrectly used structure.syntax. They are not interchangeable.
Since nobody mentioned that was wrong, I suspect you may have (incorrectly) applied that change to the code I posted.

Please post your exact source code demonstrating the compiler error. It should be complete enough to compile without any additional editing, and should compile with no errors, when the erroneous line is commented out (e.g. inside #if 0/#endif).

Another approach is the start with the other file, and temporarily add a few lines to confirm the compiler is working correctly. Note this is not a good example, since this will not compile without editing:

for (i = 0; i < 5; i++) {
    Test_Date[i] = taMsgIn->data[9+i];  // 9..14
    taMsgIn->data[9+i] = 0;                     // Temporary to test the compiler
    taMsgIn->data[9+i] = (UINT32) Test_Date[i]; // Temporary
  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.