Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Roble

characters (integer value)

This topic is 5584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would I make a program that takes the integer value of a character, and turns it into the character?

Share this post


Link to post
Share on other sites
Advertisement
You''ll have to cast the integer to a character.

  
int num;
// Get the number you want

cin>> num;
// The (char) before num "casts" the integer to a character

// So cout will treat the integer as a character

cout<< (char)num;


Is that what you wanted?


:::: [ Triple Buffer V2.0 ] ::::

Share this post


Link to post
Share on other sites
Yeah, cool thanks. I have yet another question. How do you print words in reverse in the following ways...

1)
Sentence is: "Hello, how are you?"
Reverse is: "?ouy era woh ,olleH"

and...

2)
Sentence is: "I am fine thanks"
Reverse is: "Thanks fine am I"

Any help would be much appreciated.

Share this post


Link to post
Share on other sites
er....sounds like a classic learning programming homework question. read the FAQ about homework and how you shouldn''t ask about it here. or explain why you need that for your game.

-me

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Excuse me? I''m in grade 10 and we learn TURING! TURING MAN!!!!!! Lol. I''m doing this because I want to learn, I''m making a scrambler. So... yeah

Share this post


Link to post
Share on other sites
programming problems are conceptual problems. if you are asked by someone to reverse a sentence, how do you do it?
quote:

Sentence is: "Hello, how are you?"
Reverse is: "?ouy era woh ,olleH"

Sentence is: "I am fine thanks"
Reverse is: "Thanks fine am I"


Tell me, how do you reverse those sentences? How do you know that the reverse version of "Hello, how are you?" is "?uoy era woh ,elloH" not something else? How do you know that "I am fine thanks" becomes "Thanks fine am I" not "Fine am thanks I"?

The way you do it is exactly the same way you are going to do it in your program.


500

Share this post


Link to post
Share on other sites
I have a major head-ache.... I dunno.... Can someone please tell me, I really want to get my app. working....

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
char in[256];
char out[256];

int j = 0;

for(int index = strlen(in); index > 0; --index)
{
out[j] = in[index];
j++;
}

edit by ze: replaced "i" with "index" to avoid blind forum text replacement. Note to poster below: the array did have an index, you just didn't see it

[edited by - zealouselixir on March 4, 2003 8:07:54 PM]

Share this post


Link to post
Share on other sites
That wouldnt work because an array cant be = to an array. strcpy has to be used to copy an array but in thatcase I dont think it will let you copy a single character of the array. I think when you did out[j] = in; would mean that that one character of the string out would be set to the entire string of in rather than the right character. I did something about what you did except I just used one variable and it works fine.


#include <stdio.h>
#include <string.h>

int main( void )
{
char string[80];
char *ptr;
int i;

printf("Enter a string:\n");

gets(string);

string[strlen(string)+ 1] = ''\0'';
ptr = string;

for(i=(strlen(string) -1);i>-1;i--)
printf("%c", string);

printf("\n");

return 0;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!