wxAtoi Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
computerquip
Experienced Solver
Experienced Solver
Posts: 72
Joined: Fri Feb 20, 2009 7:13 pm
Location: $(#wx)\src

wxAtoi

Post by computerquip » Fri Feb 27, 2009 4:15 pm

I haven't really seen much documentation on the global function but I think its somewhat strange that it cannot use a wxChar. In anycase:

Code: Select all

error: invalid conversion from `wxChar' to `const wchar_t*'
How do I properly go about the conversion?
Last edited by computerquip on Fri Feb 27, 2009 6:27 pm, edited 1 time in total.

rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Post by rodrigod » Fri Feb 27, 2009 5:37 pm

you are passing a char when it receives a char*. wxAtoi is nothing but a macro to the real atoi function, so thats all the documentation you need. And wxChar is a macro for char.

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Fri Feb 27, 2009 5:42 pm

Hi,

wxAtoi is not really all that different than atoi other that it also supports unicode.

Not sure what your code looks like, but are you trying to pass a wxChar directly to it? It's expecting a pointer instead of a character. Maybe post the code where you're trying to use it.

Jim
OS: Vista SP1, wxWidgets 2.8.7.

computerquip
Experienced Solver
Experienced Solver
Posts: 72
Joined: Fri Feb 20, 2009 7:13 pm
Location: $(#wx)\src

Post by computerquip » Fri Feb 27, 2009 5:55 pm

Meant to give credit to the first guy who answered.

Code that calls it through a button event:

Code: Select all

wxString input = InputBox->GetValue();
OutputBox->SetValue( grid->Decode(&input) ); //grid = new MatrixGrid()
Decode function that takes the return value from encode. Never takes a value directly from the Encode function.

Code: Select all

wxString MatrixGrid::Decode(wxString* input)
{
    wxString output;

    for (unsigned int i = 0; i < input->Length(); i += 2)
    {
        wxMessageBox(input->GetChar(i+0), _("+0"));
        wxMessageBox(input->GetChar(i+1), _("+1"));
        output += GetCellValue( wxAtoi(input[i]), wxAtoi(input[i+1]) );
    }
    return output;
}
Keeps crashing on me. In theory it works and it has worked before!

The inverse function is:

Code: Select all

wxString MatrixGrid::Encode(wxString input)
{
    bool resetFor;
    wxString output;

    for ( unsigned int a = 0; a < input.Length(); ++a)
    {
        resetFor = false;
        for ( int i = 0; i < GetNumberRows(); ++i)
        {
            for ( int j = 0; j < GetNumberCols(); ++j)
            {
                if (input[a] == GetCellValue( i, j ))
                {
                    output << i << j;
                    resetFor = true;
                    break;
                }
            }
            if (resetFor == true)
            {
                break;
            }
        }
    }
    return output; //Change to a pointer. Strings are heavy when passing around directly.
    //Works great. Maybe a better way than three for loops though lol. 
}
What'ya think?
EDIT: class MatrixGrid : public wxGrid //MatrxGrid extends wxGrid

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Fri Feb 27, 2009 6:57 pm

Hi,

From what I can see in your code, it looks like you're creating a string of indexes for the first match in your grid of each character in the input string.

First, I presume the grid is not greater than 10 characters...
You don't really need to use wxAtoi, in fact it will cause problems in the decode.
Presume string looks like: "210589" (for matches in postion 2,1 0,5 and 8,9. The first call to wxAtoi returns 210589, then next one returns 10589, etc.
I think all you need to do is:

Code: Select all

{
  wxMessageBox(input->GetChar(i+0), _("+0"));
  wxMessageBox(input->GetChar(i+1), _("+1"));
  int row = input->GetChar(i+0) - '0'; // you could check to make sure that GetChar(...) is between '0' and '9'...
  int col = input->GetChar(i+1) - '0';
  output += GetCellValue(row,col);
}
Hope that helps,

Jim
OS: Vista SP1, wxWidgets 2.8.7.

Post Reply