I am having problems understanding my message error and one part of my code.
See the attached file. I'm using an arduino uno.
I want to focus on the Datatransfer function.
double Datatransfer(char *data_buf,char num)//convert the data to the float type
{ //*data_buf?the data array
float temp=0.0; //the number of the right of a decimal point
unsigned char i,j;
if(data_buf[0]=='-')
{
i=1;
//process the data array
while(data_buf[i]!='.')
temp=temp*10+(data_buf[i++]-0x30);
for(j=0;j<num;j++)
temp=temp*10+(data_buf[++i]-0x30);
//convert the int type to the float type
for(j=0;j<num;j++)
temp=temp/10;
//convert to the negative numbe
temp=0-temp;
}
else//for the positive number
{
i=0;
while(data_buf[i]!='.')
temp=temp*10+(data_buf[i++]-0x30);
for(j=0;j<num;j++)
temp=temp*10+(data_buf[++i]-0x30);
for(j=0;j<num;j++)
temp=temp/10 ;
}
return temp;
}
I need help understanding the process or obtaining the the longitude or latitude number. I know it is stored as a character array, then pointed to the Datatransfer function to become a value. Is it a float number?
The error I keep getting is:
PrimaryCode.ino: In function 'void loop()':
PrimaryCode:371: error: invalid use of void expression
PrimaryCode.ino: At global scope:
PrimaryCode:376: error: expected primary-expression before 'float'
PrimaryCode:376: error: expected ',' or ';' before 'float'
PrimaryCode:377: error: expected primary-expression before 'float'
PrimaryCode:377: error: expected ',' or ';' before 'float'
At this point:
calc_dist(latitude(),longitude(), inputlon, inputlat);// input long and latitude
in the void loop.
My main focus is using the Haversine formula to find a distance from the GPS coordinates and my input coordinates.
Any help from understanding the code to understanding the error message would help please! I'll post more about the project if any other info is needed.
Your braces are not balanced leaving a lump of code at the end with no function.
Why are you calling functions that return a value and doing nothing with it.
Serial.print("UTC:");
UTC();
Will just print the string "UTC" it will not print anything that the UTC() function returns.
Utc() is in the void loop() part of code. The serial monitor will just output the number there. Same goes for all the other created functions. They return a string I believe. My problem is how the datatransfer function works.
If you are not going to fix stuff you are told about how do you expect the program to ever work.
Why ask a question if you are going to argue. If you know better than me then fix it yourself.
Those functions return values, if you do not do anything with them then why do they return stuff.
One of the tricks to understanding error messages is that they do not always get flages up in the place where the error is.
double Datatransfer(char *data_buf,char num)//convert the data to the float type
{ //*data_buf?the data array
float temp=0.0; //the number of the right of a decimal point
.............................
return temp;
}
Even when you do not care / use function return, it is a bad practice to do this.
Actually there is yet another hidden, but minor , flaw in just these three lines of code.
And funky usage of English,or maybe a typo, but what do I know.
On light side - 0.0 and 0 are same for ALL types of variables.
And really heed advise given, compilers are not that smart and your error is way before the Datatransfer function.
Cheers
Vaclav
So what you are saying is that the error is not on that line?
In many cases the error message is not at the line that contains the error. So a way of fault finding is to comment out the line and see if it compiles.
When I did that there were other errors that I pointed out, you fix those first because they are errors and you can see them. In fact fixing the brace showed that two out of the extra four lines had faults in them as well.
In your case the line:-
Expected to receive values from the functions latitude and longitude. These functions were declared a void which means they don't return any values. Hence the error message.
However that code is very very weird, using while(1) to form an infinite loop and then breaking out of it with a return, this is very poor coding practice.
Also as said before you don't have a handle on what is meant by a returned value from a function.
There is a lot more work to do on this code than simply just that one line.