-
Ok, so unless you are using a strange compiler that accepts this, 2_ARRAY is STILL not a valid name in C.
Fixing that will remove SOME of the problems with your code.
The code is very badly indented - you really need to fix that up, which hides the fact that you are misising two end-braces in the code.
You should not use "struct name" when name is a typedef'd name.
loop, sort, a and b are unused in the main function.
dbmARRAY1 is not defined.
You are includig regex.h, but not using any regular expressions.
--
Mats
-
I have changed the names of the original structs....but here is the corrected one....
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 structn ARRAY1{
char time[ARRAY_SIZE];
char date[ARRAY_SIZE];
}ARRAY1,ARR2;
typedef struct first{
char name[10];
ARRAY1 *main;
}first;
typedef struct second{
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;
ARR2 ARR2_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 ARR2 *new_ptr;
str_ptr = &ARRAY1_info;
new_ptr = &ARR2_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);
}
Can you confirm if this line is correct ?
strcpy(first_info.main[count].time,tokens[i]);
-
> 2_ARRAY *other;
Why do you persist with this, when it's plainly wrong.
Rename it to ARRAY2
Or something even more descriptive.
-
Yes i must have missed it when I substituted the array names...
could you please substitute 2_ARRAY as ARR2
-
No, you do it in YOUR code, then tell us what happened.
-
still getting the
"test.c", line 136: syntax error before or at: *
-
Funny, because line 136 in your code appears to be:
Code:
j = 0;
for(j=0; j < cnt; j++) {
printf("%d %s %s", j,second_info.other[j].time,second_info.other[j].date);
But there isn't a "*" in the line at all.
Are you posting errors belonging to another bit of code?
--
Mats
-
Can you confirm if this line is correct?
strcpy(first_info.main[count].time,tokens[i]);
-
It depends on what you mean by "correct". The line is syntactically and semantically correct, but I would still expect the program to blow up at this point, since I don't see anywhere where you actually make that main pointer point to anything in particular, let alone an actual array of things.
(And I assume that you have fixed the typo of "structn" in your code?
-
Can you help me with pointing the pointer
I am not sure where to initialize the pointer.
-
The key word you are looking for is "malloc".
-
yep got it...its working....thank you.