Is sscanf compatible with wxwidgets? 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
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?

Post by McSteve »

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: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is sscanf compatible with wxwidgets?

Post by doublemax »

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?

Post by McSteve »

Thanks so much its now working.
Post Reply