Char to int conversion?
c++, winapi
Solution
The atoi() function converts char* into int. It is under `<cstdlib>`
int atoi ( const char * str );
In this case,
int i = atoi(fade1Buffer);
See also, strtol() as @Keith Thompson and @Chris mentioned. It is a little harder to use, but it handles errors better.
char * pEnd;
long int i = strtol(fade1Buffer,&pEnd, 10);//10 is the base (decimal in this case)
//pEnd == fade1Buffer if there is an error.
If you convert it to a C++ style std:: string, you can use several other functions as well
#include <string>
std::string str(fade1Buffer);
int i = stoi(test);
Reference: http://en.cppreference.com/w/cpp/string/basic_string/stol
Problem
I am trying to grab the rgb values from 3 editboxes so that I can change the color of a window during run time. The following code is not giving me the numeric values that I need. ``` const int bufferSize = 1024; char fade1Buffer[bufferSize] = ""; char fade2Buffer[bufferSize] = ""; char fade3Buffer[bufferSize] = ""; HWND Editbox1 = GetDlgItem(hWnd,IDC_MAINFADE1_EDIT); SendMessage(Editbox1, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)fade1Buffer); HWND Editbox2 = GetDlgItem(hWnd,IDC_MAINFADE2_EDIT); SendMessage(Editbox2, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)fade2Buffer); HWND Editbox3 = GetDlgItem(hWnd,IDC_MAINFADE3_EDIT); SendMessage(Editbox3, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)fade3Buffer); //fill our main window background FadeVert(hWnd, RGB(fade1Buffer, fade2Buffer,fade3Buffer), RGB(255, 255, 255), (int) Client_Rect.top, (int) Client_Rect.left, (int) Client_Rect.right, (int) Client_Rect.bottom); ```