|
-
Nov 17th, 2001, 12:13 AM
#1
Thread Starter
Member
changing a set of char to string
if i type in "twelve" on a cin syntax, can c++ change the twelve into number eg : t-116, w-119 and vice versa
i tried using
char letter[] = "twelve";
and the output is twelve
but i want it as integer. maybe the sum of all the ascii characters
can anyone help me?
Code:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>> ___ __ ____ ____ _ ____ <<
>> \ \ / / _ | | __| | | | __| <<
>> \ \ / / |_| | | |__ | | | |__ <<
>> \ \/ /| _ < |__ \ | | | __| <<
>> \ / | |_| | __) ) | |___ _ | |__ <<
>> \__/ |_____| |____/ |_____||_||____| <<
>> <<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Visual Basic 5 SP3 Learning Edition.
Sub QuoteOfTheDay()
If ASCII.ugly = True Then
WhatTheHeck.ICare = True
End If
End Sub
-
Nov 17th, 2001, 03:25 AM
#2
you'd need to make a list of all the number words that are legal and then search the array for the word typed in and return the appropriate number.
Code:
int NumWordToInt(char* szNumWord) // requires string.h and stdlib.h
{
const static char nums[10][] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine" };
int i;
char* pc;
char temp[100]:
// convert word to lower case
for(pc = szNumWord; *pc; pc++)
*(temp + (pc - szNumWord)) = tolower(*pc);
*(temp + (pc - szNumWord)) = '\0';
// search for the string
for(i = 0; i < 10; i++)
{
if(strcmp(nums[i], temp) == 0) return i; // found a match
}
return -1; // error return
}
You can always make the function more sophisticated, but you get the idea.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|