![]() |
homecontact ussitemapadvertising | |||
|
|
||||
The Free MMORPG Games- Free MMORPG - P2P Games - Open Beta - Closed Beta - Browser Based - Non-English - Other Free Games - Top 50
|
|
#1 (permalink) |
|
Banned
Join Date: Oct 2007
Posts: 54
MMOFaces Profile:
None Yet
|
Can someone tell me how to extract each letters out of a string in order?
like cin>>Sentence1; inputs:hi whats up how would you extract each letter and be able to reuse them invididualy? I would like to make a translator from binary to english/english to binary. Would this require an array? |
|
|
|
|
|
#2 (permalink) |
|
Retired Staff
Join Date: May 2006
Posts: 2,026
MMOFaces Profile:
None Yet
|
hrm, I can show you a quick example in C, but I dont have time to explain it yet
Code:
#include <stdio.h>
#include <unistd.h>
int main (void) {
char *ptr = "Hello, World";
for (int i = 0; *(ptr + i); i++) {
putchar(*(ptr+i));
fflush(stdout);
usleep(500000);
}
putchar('\n');
}
Hope it helps =/ |
|
|
|
|
|
#4 (permalink) |
|
Snakes Big Toe
|
Well, okay, I'll explain what TLM did, and I'll simplify it. (And won't that run into a segmentation fault, because you're running off the end of array there?)
Code:
int main()
{
char Line[] = "Hello World!\0"
for (int C = 0; C < strlen(Line); C++)
cout << "Character " << C << ": " << Line[C] << endl;
return 0;
}
The character 'H' is Line[0]. The Character 'W' is Line[6]. Alterinatively, if you want to do it with cin, and get the user's input, you can write the first line of the program (the Line[], line), like this: Code:
char Line[100]; cin >> Line; Hope that answers your question! ![]()
__________________
This was a triumph. I'm making a note here, HUGE SUCCESS.
Outsider 3D Space Shooter/RPG in Development http://advena.awardspace.com/ |
|
|
|
|
|
#5 (permalink) |
|
Retired Staff
Join Date: May 2006
Posts: 2,026
MMOFaces Profile:
None Yet
|
Yeah I just read the OP again and that really wasnt a good example I gave
![]() Sorry about that, it was sort of the same thing, mine would print each letter of the string individually with a small pause between each character, plus it was quick dirty C with pointers and *nix commands ![]() So yeah, ignore my example if you wish to stay sane. I gotta stop posting in here, i'm gonna confuse all the C++ kiddys. Last edited by TwitcH; 10-23-2007 at 12:52 PM. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Copyright © 2004-2007 BlueCastle Media |