Help : invalid conversion from 'char*' to 'char'

Hey all,
Still a little new to all this so any help would be great. I'm making a sketch to parse and store the Longitude and Latitude from my GPS as doubles so i can do math on them later.

The only problem is I'm getting this error :

"In function 'char gps_read()':
error: invalid conversion from 'char*' to 'char' In function 'int gps_decode(char)':
In function 'double get_latitude(int, char)':
In function 'double get_longitude(int, char)':"

Here's the code :

int rxPin = 0;
int txPin = 1;
char GPR[7] = "$GPRMC";

char gps_read();
int gps_decode(char);
double get_latitude(int, char);
double get_longitude(int, char);

void setup()  {
  char line[300] = "";
  pinMode (rxPin, INPUT);
  pinMode (txPin, OUTPUT);
  Serial.begin(4800);
  for (int i=0; i<300; i++)  {
    line[i] = ' ';
    }
  }

void loop()  {
  char a = gps_read();
  int b = gps_decode(a);
  double x = get_latitude(a, b);
  double y = get_longitude(a, b);
  Serial.print(x);
  Serial.print(y);
}

char gps_read()  {
  
  int GPS;
  int counta=0;
  char line[300] = "";
  
GPS=Serial.read();         // Read a byte of the serial port
 line[counta]=GPS;        // If there is serial port data, it is put in the buffer
    counta++;                      
    //Serial.print(GPS, BYTE); // Prints out raw GPS data
        return line;             
       }
    
int gps_decode(char)  {
  
  char GPR[7] = "$GPRMC";     
  
           int count=0;
           int good=0;
           for (int i=1;i<7;i++){     // Verifies if the received command starts with $GPR
              if (line[i]==GPR[i-1]){
                good++;
        }
      }
      if(good==6){               // If yes, continue and process the data
        for (int i=0;i<300;i++){
          if (line[i]==','){     // check for the position of the  "," separator
            index[count]=i;
            count++;
          }
          if (line[i]=='*'){     // check for the position of the  "*" separator
            index[12]=i;
            count++;
          }
        }
      }
      return index;
    }
    

double get_latitude(int, char) {
  int index[13];
  char line[300];
  double dbl_latitude;
  
  for (int i=0;i<12;i++){
          for (int j=index[i];j<(index[i+1]-1);j++){
           if (i == 2){                       //  Latitude
             for (int j=index[i];j<(index[i+1]-1);j++){ 
                latitude[y] = line[j+1];
                y++;     }
                dbl_latitude = atof(latitude);
                Serial.print("Latitude = ");
                Serial.println(dbl_latitude);
                break;   
              }
            }
          }  
          return dbl_latitude;
        }
        
double get_longitude(int, char)  {
  int index[13];
  char line[300];
  double dbl_longitude;
  
  for (int i=0;i<12;i++){
      for (int j=index[i];j<(index[i+1]-1);j++){
         if (i == 4){                      //  Longitude
              for (int j=index[i];j<(index[i+1]-1);j++){
                longitude[x] = line[j+1];
                x++;  }
                dbl_longitude = atof(longitude);
                Serial.print("Longitude = ");
                Serial.println(dbl_longitude);
                break;  //
            }
          }
        }
        return dbl_longitude;
      }

Thanks,
Cory

In the Arduino IDE you don't need to declare functions at the top of the sketch, that's done for you behind scenes.

Also, you can't use variable names as variables, such as:
char
int
double
unsigned

etc etc, so you'll need to change some of your parameters:
double get_latitude(newInt, newChar); // or anything that's not int, or char! :slight_smile:

But you should look into the TinyGPS library, it handles alot of the strings and such for you:
http://arduiniana.org/libraries/tinygps/

@CaptainObvious : I always thought that in C/C++ when you created a function you have to put the variable types that are coming into the function within the () . Is that wrong?

For example when I have :

Double get_latitude(Int, Char){"insert function code here"}

For the beginning of the program I always thought that meant the program will be returning a Double and is taking in a Int and Char input. If I'm wrong, what is the correct way?

Thanks,
Cory

Is that wrong?

In C/C++ it is not wrong.
It is required (particularly in C++) to have a function prototype, but in Wiring, it is done automatically for you.

However, the type of "gps_read" is "char", but the type of the returned variable "line" is "char [300]" (that's a lot of stack!) or "char*".

In the declaration of "gps_decode" (not the prototype), you've got an argument (char), but you haven't named it.

Prototypes don't need to name the arguments, just give the type, but when the function is declared, you have to give the arguments names, otherwise you can't refer to them.

Well you don't need to set it up in the beginning, but I didn't even think about that.. to set it up, just set up the normal function before or after setup/loop, whichever you prefer.

And you just choose the variables you want to use when you set up the function, for example:

void myFunction(int myInt, char myChar)
{
// do some jumping jacks
}

or

double myFunction(double myDoub, double myDoub2)
{
// do different jumping jacks!
return myDoublenumber;
}

You just need to name them in parameters of the function, and that's it. Not required at the top like most variations of C++.

Sorry if I'm confusing you.. I'm tired, so I'm all over. But calling the variable types in the function is correct, just don't need to name(?) the function at the top.

EDIT:

Or just listen to AWOL, he knows what he's talking about. :smiley: