characters (integer value)
How would I make a program that takes the integer value of a character, and turns it into the character?
I M Teh n00B11!!!1
You''ll have to cast the integer to a character.
Is that what you wanted?
:::: [ Triple Buffer V2.0 ] ::::
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 ] ::::
[size=2]aliak.net
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.
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.
I M Teh n00B11!!!1
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
-me
March 04, 2003 03:45 PM
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
programming problems are conceptual problems. if you are asked by someone to reverse a sentence, how do you do it?
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
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
I have a major head-ache.... I dunno.... Can someone please tell me, I really want to get my app. working....
I M Teh n00B11!!!1
March 04, 2003 06:21 PM
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]
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]
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;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement