Ascii value

Apr 8, 2009 at 9:31pm
1
2
3
char s2[20];
int i = 0;
int buff = 's2[i]';


I am trying to copy the ascii value of characted in s2[0] to buff, but compiler gives error: "too many characters in constant" at line 3 above. What's the problem?
Last edited on Apr 8, 2009 at 9:32pm
Apr 8, 2009 at 9:33pm
remove the quotes: buff = s2[i];
Apr 8, 2009 at 9:41pm
That solved it. I thought 'a' gives ascii value of a and if s2[20] is a char array, then shouldn't 's2[1]' give ascii value?
Apr 8, 2009 at 9:58pm
'' is not an operator, it is used for character literals.
char letter = 97; would be the same as char letter = 'a';
'a' returns a number (97 in this case) with type char.

If it worked the way you think this would be possible:
1
2
3
char a = 'b';
cout << 'a';
//output: b 


check this tutorial: http://www.cplusplus.com/doc/tutorial/constants/
Topic archived. No new replies allowed.