int get_code(char c)
{
string alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
return static_cast<int>(alpha.find(c));
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>because my compiler doesn't like it...
Well, I was assuming some measure of intelligence on your part. I won't make that mistake in the future:
#include <cctype>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int get_code(char c)
{
string alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
return static_cast<int>(alpha.find(c));
}
int main()
{
string s = "This is a test";
cout<<"Code values of \""<< s <<"\" are:\n";
for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
if (isalpha(*it))
cout<< left << setw(3) << get_code(*it);
}
cout<<endl;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
U can define a function called as " convert "
th prototype will look like this : int convert( char)
for(i=0;i
harshchandra
Junior Poster in Training
68 posts since Nov 2004
Reputation Points: 7
Solved Threads: 1
U can define a function called as " convert "
th prototype will look like this : int convert( char)
for(i=0;i
So, do you just post random replies without reading the original question? Come to think of it, is this trick the only one you know? It seems like the only thing you post.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Can you have something like:-
12A3K = AAAAAAAAAAAAKKK
Where the number can be 2 digits or greater.
If not, it should be simple... loop through each char. But this is h/w so post your attempts.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Is is possible to take an array full of characters and then make the characters into numbers ?
To convert from 1 char to an int just subtract '0' from it. For example :
char ch = '1';
int i = ch - '0'; //i = int(1);
So just apply that to the whole array.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
So all chars to be possible are numbers (0x30 .. 0x39) only ?
Why only should chars be converted into integers, aren't they already integers (0x00 ... 0xff) internally?
-- tesu
Actually, I mis-read his post. Sorry.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608