Proba 4

                Never    
C++
       
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
	char name[30];
	char surname[30];
	char JMBG[14];
}Person;

typedef struct {
	char brand[20];
	char registration[10];
	Person owner;
}Car;

void showbinary(FILE *inb) {
	fseek(inb, 0, SEEK_SET);
	Car x;

	while (1)
	{
		fread(&x, sizeof(Car), 1, inb);
		if (feof(inb))
		{
			break;
		}
		printf("%s	%s	- %s %s	%s\n", x.brand, x.registration, x.owner.name, x.owner.surname, x.owner.JMBG);
	}

	return;
}

void showcity(FILE *inb, char *a) {
	fseek(inb, 0, SEEK_SET);
	Car x;

	while (1)
	{
		fread(&x, sizeof(Car), 1, inb);
		if (feof(inb))
		{
			break;
		}
		if (strncmp(a,x.registration,2)==0)
		{
			printf("%s	%s	- %s %s	%s\n", x.brand, x.registration, x.owner.name, x.owner.surname, x.owner.JMBG);
		}
	}

	return;
}

void changeowner(FILE *inb) {
	char registration[10];
	Person x;
	Car L;

	printf("Enter registration: ");
	gets(registration);

	printf("Enter the name of new owner: ");
	gets(x.name);
	printf("Enter the surname of new owner: ");
	gets(x.surname);
	printf("Enter the JMBG of new owner: ");
	gets(x.JMBG);

	fseek(inb, 0, SEEK_SET);

	while (1)
	{
		fread(&L, sizeof(Car), 1, inb);
		if (feof(inb))
		{
			break;
		}
		if (strcmp(registration, L.registration) == 0)
		{
			L.owner = x;
			fseek(inb, (-1)*(signed)sizeof(Car), SEEK_CUR);
			fwrite(&L, sizeof(Car), 1, inb);
			fseek(inb, 0, SEEK_CUR);
		}
	}

	return;
}

int main(void) {
	FILE *inb;
	char a[3];

	inb = fopen("automobili.bin", "rb+");

	printf("Enter the city (NI, KV, BG...): ");
	gets(a);
	showcity(inb, &a);

	printf("\n");

	changeowner(inb);
	printf("\n");

	showbinary(inb);

	fclose(inb);

	printf("\n");
	system("pause");

	return 0;
}

Raw Text