www.digitalmars.com         C & C++   DMDScript  

D - odd error

reply "Mårten Ask" <majbritt37 hotmail.com> writes:
Why doesn't this code work? I'm using dmd 0.69. It worked with 0.68..

void main()
{
 char[] s = "Hello";
 if(s[0] == "H")
 {
  printf(s);
 }
}

I get:

hello.d(4): incompatible types for ((cast(int)(s[0])) == ("H")): 'int' and
'char[1]'
Aug 16 2003
parent reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
"H" is a char[1]  s[0] is a char
try 'H' (char literal, not string literal) or "H"[0] !
there has been a change \n is not '\n' and 'foo' is not a string anymore.

"Mårten Ask" <majbritt37 hotmail.com> wrote in message
news:bhm5nk$7jf$1 digitaldaemon.com...
 Why doesn't this code work? I'm using dmd 0.69. It worked with 0.68..

 void main()
 {
  char[] s = "Hello";
  if(s[0] == "H")
  {
   printf(s);
  }
 }

 I get:

 hello.d(4): incompatible types for ((cast(int)(s[0])) == ("H")): 'int' and
 'char[1]'

Aug 16 2003
parent reply "Mårten Ask" <majbritt37 hotmail.com> writes:
Thanks, it worked right away with single quotes. I feel stupid. :)

"Mike Wynn" <mike.wynn l8night.co.uk> skrev i meddelandet
news:bhm8d5$bgh$1 digitaldaemon.com...
 "H" is a char[1]  s[0] is a char
 try 'H' (char literal, not string literal) or "H"[0] !
 there has been a change \n is not '\n' and 'foo' is not a string anymore.

 "Mårten Ask" <majbritt37 hotmail.com> wrote in message
 news:bhm5nk$7jf$1 digitaldaemon.com...
 Why doesn't this code work? I'm using dmd 0.69. It worked with 0.68..

 void main()
 {
  char[] s = "Hello";
  if(s[0] == "H")
  {
   printf(s);
  }
 }

 I get:

 hello.d(4): incompatible types for ((cast(int)(s[0])) == ("H")): 'int'


 'char[1]'


Aug 16 2003
parent reply "Matthew Wilson" <matthew stlsoft.org> writes:
 Thanks, it worked right away with single quotes. I feel stupid. :)

Don't feel stupid. Feel her smarter older sister! (Sorry, am a bit low on blood sugar at the moment ...)
Aug 17 2003
parent John Reimer <jjreimer telus.net> writes:
 (Sorry, am a bit low on blood sugar at the moment ...)
 

Well! You know how to fix that! LOL
Aug 17 2003