| | |
Converting a char array into numbers
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
C++ Syntax (Toggle Plain Text)
int get_code(char c) { string alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; return static_cast<int>(alpha.find(c)); }
New members chased away this month: 3
>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:
Well, I was assuming some measure of intelligence on your part. I won't make that mistake in the future:
C++ Syntax (Toggle Plain Text)
#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; }
New members chased away this month: 3
•
•
•
•
U can define a function called as " convert "
th prototype will look like this : int convert( char)
for(i=0;i<MAX;i++)
number = convert(a[i]);
int convert(char c)
{ return c - '0' ;
}
New members chased away this month: 3
![]() |
Similar Threads
- unable to add char array of numbers to another char array (C++)
- converting a char array to a single char (C)
- How to assign my own numeric values to a char array? (C++)
Other Threads in the C++ Forum
- Previous Thread: HELP- internal compiler error?
- Next Thread: compilers
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings struct template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






