prototype function error

I have this header in my project:

#ifndef ARDUINOSHARE_H_INCLUDED
#define ARDUINOSHARE_H_INCLUDED

#include "Arduino.h";
int pin=A5;
char message[]="";
char letters[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','w','y','x','z',};
int connectionnum[]={0,0,0,0,0,0,0,0,0,0};
int outputdata;
char stringoutput[]="";
int n=0;


void start(pin,n){
connectionnum[n]=pin;
pinMode(pin, INPUT);
return;
}

void recievemsg(n) {
for(int i=0;i!=1023;i++){
if(i == 1022){i=0;}
if(outputdata == 1023){break;}
outputdata=analogRead(connectionnum[n]);
stringoutput=(stringoutput+letters[outputdata]);}

return stringoutput;
}

void sendmsg(message[],n){
for(i=0;i>(sizeof(message)/sizeof(*message));i++){
    if(message[i] == letters[i]){analogWrite(connectionnum[n], i);}
    if(i == (sizeof(message)/sizeof(*message) ){analogWrite(connectionnum[n], 1023);}

}


return;
}







#endif

it's supposed to read and write data across two different Arduinos using the analog voltage range, and when I verify/compile the project it returns only 2 errors from that header:

In file included from uno_ver.ino:4:0:
arduinoshare.h:14:12: error: variable or field ‘start’ declared void
arduinoshare.h:20:18: error: variable or field ‘recievemsg’ declared void

You need to declare the types of the variables in the functions, for example:

void start(int pin,int n){
void recievemsg(int n) {
void sendmsg(char message[],int n){

popa6200:
I have this header in my project:
it's supposed to read and write data across two different Arduinos using the analog voltage range, and when I verify/compile the project it returns only 2 errors from that header:

In file included from uno_ver.ino:4:0:
arduinoshare.h:14:12: error: variable or field ‘start’ declared void
arduinoshare.h:20:18: error: variable or field ‘recievemsg’ declared void

Try spelling receivemsg correctly. <"I" before "E", except after "C">

stringoutput=(stringoutput+letters[outputdata]);

I think above code line is also wrong, because we are assigning char stringoutput[] to stringoutput*, which is incompatible.

Henry_Best:
Try spelling receivemsg correctly. <"I" before "E", except after "C">

Like "science", "efficient", "species"... :wink:

BijendraSingh:

stringoutput=(stringoutput+letters[outputdata]);

I think above code line is also wrong, because we are assigning char stringoutput[] to stringoutput*, which is incompatible.

Correct, and to add to the problem, stringoutput[] has been declared as a pointer to an array of length 1 - the initialiser sets the length if the length is not specified and in this case the initialiser is an empty string ("") which is just a null terminator.

You can't just concatenate strings like that without using realloc()/malloc()/dealloc() to change the amount of room in the array. Alternatively you can declare an array with enough space for your longest message to begin with and then use strcat() to append characters.

On top of that, you really shouldn't be putting all that code in the header. Put only a prototype in the header and add the rest of the code into a separate .cpp file which #includes the header.

AWOL:

Henry_Best:
Try spelling receivemsg correctly. <"I" before "E", except after "C">

Like "science", "efficient", "species"... :wink:

I heartheir are exceptions. :slight_smile: :slight_smile:

@AWOL, Henry_Best:

weird, isn't it.

econjack:
@AWOL, Henry_Best:

weird, isn't it.

Boy, howdy, neighbor, it is.

PaulS:

econjack:
@AWOL, Henry_Best:

weird, isn't it.

Boy, howdy, neighbor, it is.

Neighbour? Is he only a skein's length away from you?