Public Group

#### Archived

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

# characters (integer value)

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

## Recommended Posts

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

##### Share on other sites
You''ll have to cast the integer to a character.

  int num;// Get the number you wantcin>> num;// The (char) before num "casts" the integer to a character// So cout will treat the integer as a charactercout<< (char)num;

Is that what you wanted?

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

##### 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 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 on other sites
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 on other sites
That was me by the way... So, can any of you help me?

##### 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 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 on other sites
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 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;}

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 17
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632660
• Total Posts
3007697
• ### Who's Online (See full list)

There are no registered users currently online

×