I'm learning pointers in C and I have problems with copying pointers to a structure.
****Full code: https://1drv.ms/t/s!Av5xYBEjrdmuqS1sfgGB7pFCxGeu
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct cal {
int date;
int time;
int importance;
char group[256];
char title[256];
char description[256];
};
long long int count = 0;
int main() {
FILE *file;
......
int *group;
group = (int *)malloc(sizeof(int) * count);
group = (int *)calloc(count, sizeof(int));
struct cal *calendar;
calendar = (struct cal *)malloc(sizeof(struct cal)*count);
calendar = (struct cal *)calloc(count, sizeof(struct cal));
for (int i = 0; i < count; i++) {
char *ptr = strtok(arrs[i], " ");
while (ptr != NULL) {
calendar[i].date = 'ptr';
ptr = strtok(NULL, " "); //date
calendar[i].time = 'ptr';
ptr = strtok(NULL, " "); //time
calendar[i].importance = 'ptr';
ptr = strtok(NULL, " "); //importance
*calendar[i].group = 'ptr';
ptr = strtok(NULL, " ");//group END
*calendar[i].title = 'ptr';
ptr = strtok(NULL, " ");//Title
*calendar[i].description = 'ptr';
ptr = strtok(NULL, " ");//Discription
}
}
for(int i=0;i<count;i++)
printf("%d %d %d %s %s %s\n", calendar[i].date, calendar[i].time,
calendar[i].importance, calendar[i].group, calendar[i].title,
calendar[i].description);
}
input has to be on input.txt. like this:
YYYYMMDD HHmm [importance] [Group(string)] [title] [discription] (\n)
YYYYMMDD HHmm [importance] [Group(string)] [title] [discription] (\n)
YYYYMMDD HHmm [importance] [Group(string)] [title] [discription] (\n)
YYYYMMDD HHmm [importance] [Group(string)] [title] [discription] (eof)
Output has to be the sum of the same groups from group 0-4. ex) 1 0 1 2 0
in the
for (int i = 0; i < count; i++) {
.....
}
Part is not working. the pointer 'ptr' does not copy to 'calendar[i].somthing'. I've tried using calendar[i].date = '*ptr'; but it is also not working.