Here is the code I am trying to run
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<regex.h>
#define ARRAY_SIZE 340
#define STRUCT_SIZE 340
#define MAXTOKENS 256
#define MAXLINE 1024 /* fgets buff */
#define MINLEN 3 /* skip lines shorter as */
#define NUL '\0'
#define TRUE 1
#define FALSE 0
char *strtok( char *str1, const char *str2 );
typedef struct{
char time[ARRAY_SIZE];
char date[ARRAY_SIZE];
}ARRAY1,2_ARRAY;
typedef struct{
char name[10];
ARRAY1 *main;
}first;
typedef struct{
char db[10];
2_ARRAY *other;
}second;
char delims[] = "=";
char **split(char *string, char *delim);
int trim(char *str);
first first_info;
second second_info;
ARRAY1 ARRAY1_info;
dbmARRAY1 ARRAY12_info;
int main()
{
printf ("TEST \n" );
FILE *data_txt,*dbm_txt;
char *delim = "=";
char **tokens = NULL;
int i = 0, mcount = 0, lcount = 0;
int loop;
int sort;
int a=0;
int b=0;
int j;
int count = 0, cnt = 0;
char line[MAXLINE],line2[MAXLINE];
struct ARRAY1 *str_ptr;
struct dbmARRAY1 *new_ptr;
str_ptr = &ARRAY1_info;
new_ptr = &ARRAY12_info;
struct first *ptr;
struct second *new;
ptr = &first_info;
new = &second_info;
data_txt = fopen("db2cfg.txt","r");
dbm_txt = fopen("db2cfg2.txt","r");
int read = 0;
while (fgets(line,100,data_txt)!=NULL)
{
trim(line);
strcpy(first_info.name,"ccmlmd");
if ((strlen(line) > 1)&&(read!=0)){
lcount++;
tokens = split(line, delim);
for(i = 0; tokens[i] != NULL; i++) {
if (i==0){
if (tokens[i]!=NULL){
// printf("%02d: time %s ", i, tokens[i]);
strcpy(first_info.main[count].time,tokens[i]);
}
}
if (i==1){
if(tokens[i]!=NULL){
// printf("%02d: date %s", i, tokens[i]);
strcpy(first_info.main[count].date,tokens[i]);
}
}
}
for(i = 0; tokens[i] != NULL; i++)
free(tokens[i]);
free(tokens);
count++;
lcount++;
}
for(i=0; i < count; i++) {
printf("%d %s %s", i,first_info.main[i].time, first_info.main[i].date);
}
i = 0;
fclose(data_txt);
// start db2cfg2
read = 0;
while (fgets(line2,100,dbm_txt)!=NULL)
{
trim(line2);
strcpy(second_info.db,"ccmlmd");
// printf("other %s",second_info.db);
if ((strlen(line2) > 1)&&(read!=0)){
mcount++;
tokens = split(line2, delim);
for(i = 0; tokens[i] != NULL; i++) {
if (i==0){
if (tokens[i]!=NULL){
// printf("%02d: time %s ", i, tokens[i]);
strcpy(second_info.other[cnt].time,tokens[i]);
}
}
if (i==1){
if(tokens[i]!=NULL){
// printf("%02d: date %s", i, tokens[i]);
strcpy(second_info.other[cnt].date,tokens[i]);
}
}
}
for(i = 0; tokens[i] != NULL; i++)
free(tokens[i]);
free(tokens);
cnt++;
} // add for(j=0 ;j<=cnt
j = 0;
for(j=0; j < cnt; j++) {
printf("%d %s %s", j,second_info.other[j].time,second_info.other[j].date);
}
fclose(dbm_txt);
return 0;
exit(0);
}