hello friends,
I am having a problem.
This code works just fine when I print as soon as I assign the string to
the pointer.
Code:
ptr->main = malloc(sizeof(d etail)*(660)+1) ;
strcpy(ptr->main[count].key,token[i]);
printf("key key %d %s ",count, ptr->main[count].key);But when I try to do this....
I am having a problem.
This code works just fine when I print as soon as I assign the string to
the pointer.
Code:
ptr->main = malloc(sizeof(d etail)*(660)+1) ;
strcpy(ptr->main[count].key,token[i]);
printf("key key %d %s ",count, ptr->main[count].key);But when I try to do this....
Code:
for(i=0; i < count; i++) { printf("%d %s %s \n", i,ptr->main[count].key); }It doesnt work. What am I doing wrong in the for loop...
Code:
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]; ARRAY2 *other; }second; in main{ FILE *data_txt, struct ARRAY1 *str_ptr; struct ARR2 *new_ptr; str_ptr = &ARRAY1_info; new_ptr = &ARR2_info; struct first *ptr; struct second *new; data_txt = fopen("data.txt","r"); 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){ ptr->main = malloc(sizeof(detail)*(660)+1); strcpy(ptr->main[count].key,token[i]); printf("key key %d %s ",count, ptr->main[count].key); } } } for(i = 0; tokens[i] != NULL; i++) free(tokens[i]); free(tokens); count++; lcount++; } // This doesnt work for(i=0; i < count; i++) { printf("%d %s %s", i,ptr->main[i].time, ptr->main[i].date); }
Comment