I would recommend you to use function strtok() to find string you need i.e. 00
or 39
.
and strtol()
to conversion from string to long integer. Anyway, stay away from atoi()
.
Why shouldn't one use atoi().
Here is example, convertion from minutes/seconds to miliseconds is up to you.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char input[] = "00:39.841 ID:6 unicast message ready to be sent";
char * ptr;
long minutes = 0,
seconds = 0,
milisecs = 0;
ptr = strtok(input, ":");
if (ptr == NULL) { fprintf(stderr, "Wrong input minutes."); return 1; }
minutes = strtol(ptr, (char **)NULL, 10);
ptr = strtok(&input[3], ".");
if (ptr == NULL) { fprintf(stderr, "Wrong input seconds."); return 1; }
seconds = strtol(ptr, (char **)NULL, 10);
ptr = strtok(&input[6], " ");
if (ptr == NULL) { fprintf(stderr, "Wrong input milisecs."); return 1; }
milisecs = strtol(ptr, (char **)NULL, 10);
printf("%ld - %ld - %ld\n", minutes, seconds, milisecs);
return 0;
}