Is sscanf compatible with wxwidgets?  [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.
McSteve
In need of some credit
In need of some credit
Posts: 6
Joined: Sat Jun 24, 2017 4:14 pm

Is sscanf compatible with wxwidgets?

Postby McSteve » Thu Jun 14, 2018 7:22 am

void Main::OnReadTimer( wxTimerEvent& event ){

char message [1000] = {0};
SerialReadLine(message, 1500);
char search[] = "Aktuelle Position:";
char *ptr = strstr(message, search) + strlen(search);
int pos = 0;
sscanf(ptr, "%d",&pos);
wxString tok;
tok << pos;
get_position->SetValue(tok);
}

My code crashes when I compile with sscanf. Help. Is there an altenative to sscanf? Thanks

User avatar
doublemax
Moderator
Moderator
Posts: 12795
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is sscanf compatible with wxwidgets?  [SOLVED]

Postby doublemax » Thu Jun 14, 2018 9:34 am

I don't think sscanf is the real problem in your code. First of all, you try to read up to 1500 bytes into a 1000 byte buffer. Then you don't check "ptr" for zero after the strstr() call.

Use a debugger and check where exactly it crashes.
Use the source, Luke!

McSteve
In need of some credit
In need of some credit
Posts: 6
Joined: Sat Jun 24, 2017 4:14 pm

Re: Is sscanf compatible with wxwidgets?

Postby McSteve » Sun Jun 17, 2018 5:54 am

Thanks so much its now working.


Return to “C++ Development”

Who is online

Users browsing this forum: ollydbg23 and 22 guests