Thanks for the reply. Here's more of the code, it's essentially a checksum function, and computedsum is defined in the first line of the function
char *checksum(char * GPSdata, char computedsum[5])
{
sum = 0;
int j = 0;
while (j < i)
{
byte data = GPSdata[j];
switch (data)
{
case '
It's printed using Serial.print(computedsum):
break;
case '*':
j = i;
break; //this indicates the end of the sentence
default:
if (sum == 0)
{
sum = GPSdata[1];
}
else
{
sum ^= data;
}
}
j++;
}
sprintf(computedsum,"%*X", 2, sum);
return computedsum;
}
Oh sorry, I thought I had initialized sum within that function. It's an int.
Your proposed solution doesn't work, it just gives the same issue. I'm sorry I really should have mentioned at first that I'm using a chipkit board not an arduino per se.
It's really not that big of a deal, I'll just pad the reported checksum from the GPS device with a 0 in front and then I should be able to compare the two, which is what I've been trying to do.
Without seeing all the code it is very difficult to tell what is happening.
There are several declarations that we cannot see and we cannot see how
this function is being called.
The declaration for the computedsum argument in the checksum() routine
looks suspicious. While you can specify an array that way, I believe that it
is no different than using "char *" which will not allocate any storage for the variable
since it is only a pointer.
Also, are you sure that the output was "05A" and not "05A", if there is a space
there, it could be that you are printing 2 checksums back to back and the first is a 0 which will
print "0" and not "00".
Just a guess, but as far as the actual format strings goes, perhaps you want "%02X" which
will give a zero filled 2 digit hex number. So that if you have numbers less than 0x10
they will get a '0' filler character rather than a space.
i.e. 0x3 will display as '03' rather than 3 and 0x0
will display as '00' rather than 0
The "" field width option as a format string to xxprintf() functions, while
useful, is not always supported.
While I've used it in the past, I'm surprised that is working for you guys,
as it doesn't seem to work with my version of the AVR toolset that came with with 0022 IDE
for linux. When I use "" in the formatting string, all the output is dropped.
(but that is a different problem to worry about later...)
Can you boil this down to a small complete program that compiles?
That would be helpful.