FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


C > Chr() in C++??





asDdsA2
Hello.... for VB is Chr() and Asc()

and for C?? Is a little and stupid question.. i know. but i can't find those functions...

Thanks
Liu
For Chr() you can cast in C/C++.

For example:

Code:

char x = 61; // ascii for "="

cout<<"x is: "<<x<<endl;
cout<<"x is: "<<(int)x<<endl;


will output:
Code:

=
61


For Asc()

C/C++ treat strings as a character array. Just index the string at 0, and cast it as an integer.
hexkid
asDdsA2 wrote:
Hello.... for VB is Chr() and Asc()

and for C?? Is a little and stupid question.. i know. but i can't find those functions...

Thanks


I don't know C++.
In C there is no concept of character as such; C only knows (integer) values.

Maybe you have something input from the user and you want to transform it into uppercase
Code:
/* assume ASCII, will not work otherwise */
char * p = name; /* 'name' is the user input */
while (*p) {
  if ((*p >= 97) && (*p <= 122)) {
    *p -= 32;
  }
  ++p;
}
printf("uppercased is '%s'\n", name)
deepak
Hi,

You need casting in C/C++
for example
Code:

int i = 65;
cout<<char(i); // It'll print character representing Ascii value of 65 i.e 'A'

char a = 'A';
cout<<int(a); // It'll print ASCII value repreented by A, i.e 65

for(i = 65; i <= 90; ++i)
       cout<<char(i);


I hope it'll help you.
asDdsA2
oh.. thanks guys.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.