Const Char *

09 Oct 2010

Hi People,

I am trying to use the serial bus to talk to another module, im having difficulty manipulating the serial data coming from the secondary module. Here is the problem i am faced with, appreciate help...

  • "Argument of type "char" is incompatible with parameter of type "const char *" (E167)" in file "/main.cpp"
  • "Operand types are incompatible ("char" and "const char *") (E42)" in file "/main.cpp"

while(1)
{
testchar[i] = module.getc();
testint = atoi(testchar[i]);
pc.printf("%c",testchar[i]);

if (testchar[i] == "0x00");   // <-- 0x00 not definded yet
{
}

i++;
}

 

Will appreciate any help... teach me the basics please...

09 Oct 2010 . Edited: 09 Oct 2010

Hi Harry

"0x00" is three characters, I think your comparison should be testchar[i] == 0x0 (ie. remove the quotes and a trailing zero). Then you are comparing to the character with value 0.

Regards
Daniel

14 Oct 2010

atoi takes a pointer to an array of chars (a string) not a single char. If you want to see if a particular char is a number you can use isdigit() if it's in the mbed library. Otherwise this might work (not tested):

 

int isdigit(char c) {
  if (c - '0' > -1 and c - '0' < 10)
    return 1;
  else
    return 0;  
}

17 Oct 2010

Thanks... all good...

17 Oct 2010

i just took the quotes out... and it worked e.g. == 0x11