Extracting data from an array in C
I am writing a program in C which will extract data from an array.
The array contains the data: char test[] = "TRACKING ID: 1365 DATE: 20030901 TIME: 1200 ROUTE: 12 DRIVER: 005 STATUS: Nobody present";
What I need to do is extract just the bit of the Tracking ID which says 1365 and store it in a typedef struct and then print the contents of the typedef struct.
This is what I have done so far:
Code:
//last updated Monday 6 October 2003
#include <stdio.h>
int main()
{
//typedef structure to hold Transaction data
typedef struct
{
int trackingId;
char transDate[9];
char transTime[5];
int route;
int driver;
char status[100];
} Transaction;
Transaction transac;
// TEST CODE
char test[] = "TRACKING ID: 1365 DATE: 20030901 TIME: 1200 ROUTE: 12 DRIVER: 005 STATUS: Nobody present";
// EXTRACT THE TRACKING ID AS AN INTEGER and store it in the typedef struct
transac.trackingId = strstr(test, "TRACKING ID"); //NULL if not found
printf(transac.trackingId);
}
The problem with this is that it prints out the whole of the contents of the char test[] array, when I really want it to just print out the tracking ID which is 1365.
Thanks for any help.
:)