Code:
int process_record(char * current_record)
{
char * buffer;
char activity_month[BUFSIZ];
char current_month[BUFSIZ];
int fields = 0;
time_t curtime;
struct tm *loctime;
char record[BUFSIZ];
int loop, count = 0;
curtime = time(NULL);
loctime = localtime(&curtime);
strftime(current_month, BUFSIZ, "%Y%m", loctime);
strcpy(record, current_record);
count = strlen(record);
for(loop = 0; loop < count; loop++)
{
buffer = strtok(record, ";");
if(buffer != NULL)
{
fields++;
if(fields == DATE_DELIM && buffer == NULL)
{
error_func("In get_activity_month().", "Error : Activity_Month has no data", SYS | FATAL);
}
else if(fields == DATE_DELIM)
{
strncpy(activity_month, buffer, 6);
}
printf("count %d\n", count);
printf("loop %d\n", loop);
printf("fields %d\n", fields);
printf("constant %d\n", DATE_DELIM);
printf("original record [%s]\n", record);
printf("whats in the box [%s]\n", buffer);
printf("start date [%d]\n", start_date);
printf("end date [%d]\n", end_date);
printf("month date [%s]\n", activity_month);
...
/* OUTPUT */
count 480
loop 78
fields 79
constant 79
original record [United Kingdom]
whats in the box [United Kingdom]
start date [200209]
end date [200309]
month date [United]
count 494
loop 78
fields 79
constant 79
original record [United Kingdom]
whats in the box [United Kingdom]
start date [200209]
end date [200309]
month date [United]
count 487
loop 78
fields 79
constant 79
original record [United Kingdom]
whats in the box [United Kingdom]
start date [200209]
end date [200309]
month date [United]
In the above snippet, what do I need to do to move along the record ?
What's happening is the first field is being captured for each record rather than a field further along the line and it's because I am not stepping through the record properly,
I have tried this
Code:
while(buffer != NULL)
{
buffer = strtok(NULL, ";");
}
but without success
tia,