Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error: void value not ignored as it ought to be in Arduino

This is a function to convert 1 digit number to 3 digit. For example convert ‘2’ to ‘002’.

void loop() {
 int x = convertdigit(time);
}

void convertdigit(int num){
  char buffer[50];
  int n;
  n=sprintf (buffer, "%03d",num);
  return buffer;
}

Error: void value not ignored as it ought to be

/sketch/sketch.ino: In function 'void loop()':
/sketch/sketch.ino:33:30: error: void value not ignored as it ought to be
     int x = convertdigit(time);
                              ^
Error during build: exit status 1

May i know how to fix it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

When you write this you are telling the compiler that convertdigit does not return anything (void):

void convertdigit(int num)

When you write this, you are telling the compiler to use the return value of convertdigit and store it in x:

int x = convertdigit(num);

Those two things are in conflict: if convertdigit doesn’t return anything, how can you store that nothing in x? Your code is kind of confusing so I’m not sure what you actually intended, but now that I have explained that error message, I hope you are able to make progress.

Hint: If you want convertdigit to return an int, change void convertdigit(... to int convertdigit(....

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading