d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Total Noob In C L4i > Ty
12Next
Add Reply New Topic New Poll
Member
Posts: 1,059
Joined: Jul 2 2009
Gold: 70.00
Jun 7 2012 03:52pm
Hi,
How can you make your console write letters?
For exemple, A, B, C and so on,
So I can write any kind of words.

ty jsp
Banned
Posts: 2,525
Joined: Jan 2 2012
Gold: 0.01
Warn: 10%
Jun 7 2012 04:40pm
Of course! For example:

Code

char text[] = "Hello world!";
int main() {
   __asm__("mov $text, %edi");
   __asm__("call puts");
}
Member
Posts: 1,059
Joined: Jul 2 2009
Gold: 70.00
Jun 7 2012 05:21pm
Quote (ikusus @ 7 Jun 2012 18:40)
Of course! For example:

Codechar text[] = "Hello world!";
int main() {
    __asm__("mov $text, %edi");
    __asm__("call puts");
}


thanks but I've been heard wrong...

Is there a way to convert numbers to Letters? Like number 65 = A
So, Let's say I want my console to drop me something like
A
B
C
D
E
... I could write something like

int Number = 65
printf ("%(whatevergoeshere)", Number)

And it would appear in the console as A

This post was edited by SoRandom on Jun 7 2012 05:22pm
Member
Posts: 4,250
Joined: Apr 17 2005
Gold: 0.01
Jun 7 2012 05:57pm
http://ideone.com/GFvBJ

This post was edited by Elles on Jun 7 2012 06:10pm
Member
Posts: 2,303
Joined: Oct 11 2007
Gold: 0.00
Jun 7 2012 08:48pm
Quote (SoRandom @ 7 Jun 2012 18:21)
thanks but I've been heard wrong...

Is there a way to convert numbers to Letters? Like number 65 = A
So, Let's say I want my console to drop me something like
A
B
C
D
E
... I could write something like

int Number = 65
printf ("%(whatevergoeshere)", Number)

And it would appear in the console as A


printf((char)number);

don 't know much bout C but in C# i'd simlply cast it like that
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jun 7 2012 11:56pm
Code
int num = 65
while(num > (char)'A' && num < (char)'Z')
{
  printf("%c", (char)num);
  num++;
}
Member
Posts: 827
Joined: Jan 16 2012
Gold: 0.00
Warn: 10%
Jun 8 2012 10:47am
Quote (Eleven11 @ Jun 8 2012 12:48am)
printf((char)number);

don 't know much bout C but in C# i'd simlply cast it like that



You're not doing anything here but to convert a number to a char. It would print "65" as being string, thats all :P
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jun 8 2012 11:41am
Quote (AbDuCt @ Jun 8 2012 01:56am)
Codeint num = 65
while(num > (char)'A' && num < (char)'Z')
{
  printf("%c", (char)num);
  num++;
}


cant believe i was this tired when i wrote that. and even more surprised no one called me on it lol


Code
int num = 65
while(num > (int)'A' && num < (int)'Z')
{
  printf("%c", (char)num);
  num++;
}


^fixed

edit:: could so go

int num = (int)'A';

if you really wanted to confuse someone lol.

This post was edited by AbDuCt on Jun 8 2012 11:42am
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Jun 9 2012 06:44am
Quote (AbDuCt @ 8 Jun 2012 19:41)
cant believe i was this tired when i wrote that. and even more surprised no one called me on it lol


Code
int num = 65
while(num > (int)'A' && num < (int)'Z')
{
  printf("%c", (char)num);
  num++;
}


^fixed

edit:: could so go

int num = (int)'A';

if you really wanted to confuse someone lol.


Why would anyone call you on that? Both versions of your code do exactly the same thing (and use < and > operators where you wanted <= and >= respectively).

http://ideone.com/uaAyq
http://ideone.com/W3ltt
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jun 9 2012 10:08am
Quote (KrzaQ2 @ Jun 9 2012 08:44am)
Why would anyone call you on that? Both versions of your code do exactly the same thing (and use < and > operators where you wanted <= and >= respectively).

http://ideone.com/uaAyq
http://ideone.com/W3ltt


i mean casting the characters as (char) inside the while loop definition. not the other line of code i put in my edit lol.

and yea forgot the '=' on those operators >.>

http://codepad.org/A4tFZxl3

This post was edited by AbDuCt on Jun 9 2012 10:11am
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll