Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,826 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,547 people online right now. Registration is fast and FREE... Join Now!




Enter a string and use a loop to find the ASCII Number of its characte

 
Reply to this topicStart new topic

Enter a string and use a loop to find the ASCII Number of its characte, Enter a string and use a loop to find the ASCII Number of its characte

ctcoyote16
5 Feb, 2007 - 09:36 AM
Post #1

New D.I.C Head
*

Joined: 5 Feb, 2007
Posts: 2


My Contributions
Hello guys. I am in a C++ class and I'm having trouble with this assignment. The assignment is to Enter a string and use a loop to find the ASCII Number of its characters.

We've been dealing with "For Loops" so basically this code needs to contain at least one.

Heres all I can think to figure out:

CODE


cout<<"Enter a word: ";
cin>>word;

for(int i=0; i>word.length; i++)

word.find()




Yeah, I dont really understand this and Im not sure what exactly needs to be in it but Im pretty sure Ill need the substr, length, and find functions.

Any help is greatly appreciated. Thanks
User is offlineProfile CardPM
+Quote Post

realNoName
RE: Enter A String And Use A Loop To Find The ASCII Number Of Its Characte
5 Feb, 2007 - 10:17 AM
Post #2

D.I.C Regular
***

Joined: 4 Dec, 2006
Posts: 311



Thanked: 5 times
My Contributions
QUOTE
The assignment is to Enter a string and use a loop to find the ASCII Number of its characters.

I dont really know what your wanting... something you need to fix is to use the length function you need to add () ex word.length() as for getting the ASC-II value one of the ways to do it is a static cast

static_cast<int>(word[i])
User is online!Profile CardPM
+Quote Post

Ryan747
RE: Enter A String And Use A Loop To Find The ASCII Number Of Its Characte
5 Feb, 2007 - 05:39 PM
Post #3

New D.I.C Head
*

Joined: 16 Oct, 2006
Posts: 26


My Contributions
CODE

cout<<"Enter a word: ";
cin>>word;

for(int i=0; i<word.length(); i++){
   cout << int(word[i]);
}


i think this is what you meant....
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Enter A String And Use A Loop To Find The ASCII Number Of Its Characte
6 Feb, 2007 - 08:25 AM
Post #4

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,029



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Yes, Ryan747 is right.
Internally, everything is a number. There's no such thing as a character. Characters are stored as integers in memory where each integer value corresponds to a character according to ASCII.

So typecasting a character into an integer does the trick.
User is offlineProfile CardPM
+Quote Post

ctcoyote16
RE: Enter A String And Use A Loop To Find The ASCII Number Of Its Characte
6 Feb, 2007 - 06:00 PM
Post #5

New D.I.C Head
*

Joined: 5 Feb, 2007
Posts: 2


My Contributions
alright thanks guys. I got to finish this code up tonight, its for homework. hope to learn all this stuff eventually, lol crazy.gif


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 09:27AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month