Help with pointers for a Dumby


#1

Hello,
just need some help passing a pointer to an array to another function. This function is in another source file. The idea is to just send the pointer to the data array which will be sent with a http POST. I have the POST part working well just want to get other data to it.
As it is I just get control characters.

ascii testdata[500];


void cfg_gprs(ascii*);

void adl_main ( adl_InitType_e InitType )
{
wm_sprintf(testdata, "machine=test&data=this is a test line of stuff\r\n"); // 48 bytes long
cfg_gprs(&testdata[0]);
}


void cfg_gprs (ascii* ptr) {
  dataptr=ptr;
  TRACE (( 1, "(cfg_gprs) Enter." ));
  adl_atSendResponse ( ADL_AT_UNS, "***Activate APN\r\n" );
  adl_atSendResponse ( ADL_AT_UNS, *ptr );

  adl_simSubscribe( evh_sim, GPRS_PINCODE);

}

#2

I think that would be found in a standard ‘C’ textbook - it has nothing specifically to do with Wavecom nor Open-AT.

For a start, do you understand that an array name is, effectively, a pointer to the first element of the array?

This almost certainly means that you don’t actually want to pass a pointer to an array at all…!

c-faq.com/aryptr/index.html

publications.gbdirect.co.uk/c_book/


#3

I think you need to revisit viewtopic.php?f=3&t=3730&p=14430&hilit=pointer+array#p14430


#4

Yes take your point but I have looked back over examples and this seems this is correct.
So in a nut shell what have I done incorrectly??


#5

OK, back to basics:

This defines ptr as a “pointer to ascii

The asterisk here is the ‘C’ pointer dereference operator; ie, it gets you the thing that the pointer is pointing at.

So, as ptr is a “pointer to ascii”, when you dereference it, you get an ascii

That is, *ptr is an ascii

So, ask yourself: is an ascii correct as the 2nd parameter in a call to adl_atSendResponse :question:


#6

Yes I would like the ascii string starting from that pointer printed down the UART