From this line you need to pull 12 and continue to work with him.
"Принято в Socket->ReceiveBuf() 12 байт:" ReceiveBuf() 12 байт...">
From this line you need to pull 12 and continue to work with him.
"Принято в Socket->ReceiveBuf() 12 байт:" Something like
#define ERROR_VALUE -1 char * s = "Принято в Socket->ReceiveBuf() 12 байт:"; int getFirstInt(char * s) { char * c; for(c = s; *c != 0; ++c) { if (isdigit(*c)) return atoi(c); } return ERROR_VALUE; } int main(int argc, const char * argv[]) { printf("Get %d bytes\n",getFirstInt(s)); } True, negative values are not being processed here ...
return c > s && c[-1] == '-' ? -atoi(c) : atoi(c); return c > s && c[-1] == '-' ? -atoi(c) : atoi(c); - avpwill return c[-1] == '-' ? -atoi(c) : atoi(c); and so work return c[-1] == '-' ? -atoi(c) : atoi(c); return c[-1] == '-' ? -atoi(c) : atoi(c); because at the first iteration and so c> s
for (c = s; ...) c equals s - avpgetFirstInt() function code in the @Harry response? The increment (++ c) is performed at the very end of each iteration. At the beginning of the first c == s , so if the first character in s digit, then in the expression c[-1] == '-' ? ... c[-1] == '-' ? ... access to non- s memory will occur, which is generally not correct (UB). - avpint getFirstInt(char * s) { char * c; for(c = s+1; *c != 0; ++c) { if (isdigit(*c)) return c[-1] == '-' ? -atoi(c) : atoi(c); } return ERROR_VALUE; } int getFirstInt(char * s) { char * c; for(c = s+1; *c != 0; ++c) { if (isdigit(*c)) return c[-1] == '-' ? -atoi(c) : atoi(c); } return ERROR_VALUE; } int getFirstInt(char * s) { char * c; for(c = s+1; *c != 0; ++c) { if (isdigit(*c)) return c[-1] == '-' ? -atoi(c) : atoi(c); } return ERROR_VALUE; } - skorpSource: https://ru.stackoverflow.com/questions/543843/
All Articles
isdigit()) - add it to the end of the line for the result. - PinkTuxsscanf(),atoi()etc. - PinkTux