Hello,


Can someone please explain to me because i do not understand the
tutorials on pointers.

anyways i have a struct:

struct driver {
 int id;
 char name[30];
 int runs;
}

//I am reading a file which goes in order ID NAME RUNS as:  1 Super Man 5
//I am reading it from a file like so:

struct drive *read(char *file){
	int x = 1;
	FILE* open;
	open = fopen(file,"r");
	while(!feof(open)){
		struct drive *drive1;
		drive1 = (struct drive*) malloc(sizeof(struct drive));
		drive1->stevilka=x;
		fscanf(open, "%d", &drive1->id);
  		fscanf(open,"%s", drive1->name);
		printf("%d", drive->id);
		printf("%s", drive->ime);
	}

	
}

What am i doing wrong here ?

Can someone take a looka at the last printf and tell me why can i print out
my value.

struct voznja *beriVoznje(char *datoteka){
	FILE* open;
	open = fopen(datoteka,"r");
	while(!feof(open)){
		struct voznja *drive;
		drive = (struct voznja*) malloc(sizeof(struct voznja));
		fscanf(open, "%d", &drive->id);
  		fscanf(open,"%s", drive->ime);
 		fscanf(open,"%s", drive->priimek);
 		fscanf(open,"%d", &drive->meritve);
		//printf("%d", drive->id);
		//printf("%s", drive->ime);
		//printf("%s", drive->priimek);
		//printf("%d", drive->meritve);
		for (int i = 0; i <= drive -> meritve; i++){
			fscanf(open,"%f", &drive->x[i]);
			fscanf(open,"%f", &drive->y[i]);
			printf("%f", drive->x[3]);
			
		}
	}
}

What is the issue with your program ?

What is the expected output and what are you getting ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.