How to get "substring" from a char array in C -


i have char array of form:

[17 chars, tab char, 17 chars, tab char, 17 chars, tab char, char representing number between 1 , 4 digits long, null-byte]

i want store chars sit between tab char , null-byte in new variable.

example 1: char array:

[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,\t,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,\t,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,\t,3,4,\0]

and want save int 34 in variable called x.

example 2: char array:

[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,\t,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,\t,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,\t,5,9,9,\0]

and want save int 599 in variable called x.

i can if know number of digits of number, not sure how solve problem of having number of unknown length.

any appreciated much.

let's string (aka char array) pointed str, since seem need number in int can use atoi(str + 3 * (17 + 1)) want.

if want in string can use strcpy(str2, str + 3 * (17 + 1)) assuming buffer pointed str2.

btw, need include stdlib.h atoi() , string.h strcpy().


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -