String function Problems


#1

Hello,
I’m getting there with my C++ but just having problems cutting characters of an array.

static ascii  gpsbuff [DATA_MAX];//global
 
//local
u8 i,j,field,startp,len;
ascii temp15[15];


temp15==strncpy(&gpsbuff[startp],temp15,len);
temp15==strcat(temp15,"\r\n");
adl_atSendResponse ( ADL_AT_UNS, temp15 );

output should be;
0
00
99.9
I get
9
9
9
9
I have to say I’m not clear on where to use the variable and where to use a pointer in these functions
Help Please


#2

Actually, what you’ve shown is all just good ol’ C - it hasn’t strayed into any C++ territory (yet)…

For that, you need a ‘C’ textbook!

You could start with publications.gbdirect.co.uk/c_book/

Note that a pointer is a variable - the value of a pointer variable is the address of something and, because it’s a variable, you can change that value at run time; ie, you can assign a new value to it.

The name of an array acts, in many ways, like a pointer - because it gives the address of the 1st element of the array - but the key difference is that you cannot assign a value to it. Its value is fixed at build time.

Also note that “==” is not the assignment operator in ‘C’ !

The “==” double-equals is a comparison operator that checks if its two operands are equal!

Thus this code contains two mistakes:

temp15==strncpy(&gpsbuff[startp],temp15,len); // This is not an assignment, and would be illegal as an assignment!
  1. You are trying to assign to an array name - which is not allowed;
  2. You are using the equality comparison operator (==) instead of the assignment operator (=)

#3
temp15 == strncpy( &gpsbuff[startp], temp15, len );

Once you’ve corrected the errors noted above, I think you also need to check carefully that you have the parameters to strncpy in the correct order for your required result…

BTW: a little whitespace goes a long way in making code more readable…


#4

Thanks for the help. yes :blush: on the ==
I’m still struggling with basics, can’t find things in the documentation.
Please for definations

what is a s32? I asummed it was a 32bit single but it looks like 32 bit integer??

for single/double precision numbers it should be

float number;
double number;

Also how do you TRACE output a floating point numbers? It seems that the standard %f is not available, %d should give 1 decimal place?

number=9.98;
TRACE((1,“number %d”,number));
gives
Number 1076098498

One more how do convert string to float? e.g temp15=“9.98”


#5

It isn’t the place of the Wavecom documentation to teach you the ‘C’ language - it is assumed that you are already a competent ‘C’ programmer.

Yes, it is a signed 32-bit integer

And u32 is an unsigned 32-bit integer.

Similarly for u16/s16 and u8/s8

But you’re right - they are not documented :angry:
I guess they used to be documented in the so-called “Basic (sic) Development Guide” - now discontinued - and Wavecom forgot to put them into the ADL User Guide when the Basic guide was discontinued… :unamused:
See: viewtopic.php?f=3&t=3692&p=14287#p14284

But you can see the definitions in wm_types.h

The problem with %f is documented - and a workaround is given.

No - %d gives an integer (‘C’ textbook again)