Connect with us

Help in Arduino Codes

Discussion in 'Microcontrollers, Programming and IoT' started by brian22, Aug 27, 2013.

Scroll to continue with content
  1. brian22

    brian22

    40
    0
    Jul 19, 2013
    hi sir/ma'am how to convert a char to a string?

    i've got this error.

    sketch_aug27a:90: error: invalid conversion from 'char' to 'const char*'
    sketch_aug27a:90: error: initializing argument 1 of 'String::String(const char*)'
    sketch_aug27a:93: error: invalid conversion from 'char' to 'const char*'
    sketch_aug27a:93: error: initializing argument 1 of 'unsigned char String::equals(const char*) const'



    Code:
    char x;
    n[20];
    
         
          if((x, n)>0)   // Number, Number length
          {
          String num=x;
          if(num.equals("12345")){
          Serial.print("Ok");
         }
         else{
         Serial.print("Done");
    }
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    11,005
    2,506
    Nov 17, 2011
    Try
    Code:
    String num=String(x);
    I have to admit I'm not familiar with programming an arduino, but this line
    Code:
    if((x, n)>0)   // Number, Number length
    
    looks suspicious, too. The language reference requires that within the parentheses stand a condition. I do not recognize a condition in (x,n).

    Another point:
    Code:
    String num=x;
          if(num.equals("12345"))
    Why do you first convert the number to a string, then compare the string to another number in string format? This is time consuming and unnecessayr. You can directly compare the numbers like:
    Code:
    if (x==12345)
     
  3. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,474
    2,820
    Jan 21, 2010
    In addition to the above...

    Code:
    if (12345==x)
    is better, because if you omit omit one "=" you get an error rather than a bug.

    I also have no idea what

    Code:
    if((x, n)>0)   // Number, Number length
    is meant to do.
     
  4. Harald Kapp

    Harald Kapp Moderator Moderator

    11,005
    2,506
    Nov 17, 2011
    Code:
    if (12345==x)
    Good trick, Steve.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-