-1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <locale.h>
 
typedef struct Motorista{
    int driver_id; // id do motorista
    int idade; // idade do motorista
    int telefone; // telefone do motorista
    char nome[50]; // nome do motorista
}motorista; // estrutura do motorista
 
typedef struct Carro{
    int car_id; // id do carro
    char marca[50]; // marca do carro
    char modelo[50]; // modelo do carro
}carro; // estrutura do carro
 
 
void add_driver(){ // função para adicionarr motorista 
    motorista driver;
    FILE *m;
    m = fopen("motoristasss.txt","ab");   
    
    if(m == NULL){
        printf("       [!]problemas na abertura do arquivo...");
    }else{
        do{
            system("cls");
            printf("\n  #-------------  Cadastro motorista  -------------#");
            printf("\n  |                                                |");
            printf("\n  #------------------------------------------------#");
            
            fflush(stdin);
            printf("\n\n      >Insira o nome do  motorista: ");
            gets(driver.nome); 
            
            
            printf("\n\n      >Insira o id do motorista: ");
            scanf("%d",&driver.driver_id);
            fwrite(&driver, sizeof(motorista), 1, m);
            
            printf("\n\n      >Insira a idade do motorista: ");
            scanf("%d",&driver.idade);
            fwrite(&driver, sizeof(motorista), 1, m);
            
            printf("\n\n      >Insira o telefone do motorista: ");
            scanf("%d",&driver.telefone);
            fwrite(&driver, sizeof(motorista), 1, m);
            
            printf("\n\n      [!]Deseja adicionar mais um motorista? (s/n)? ");
            
        }while(getche() == 's');
        fclose(m);
    }
    
   
}
void listar_driver(){
    system("cls");
    motorista driver;
    FILE *m;
    m = fopen("motoristasss.txt","rb");   
    
    if(m == NULL){
        printf("       [!]problemas na abertura do arquivo...");
    }else{
        while(fread(&driver, sizeof(motorista), 1, m)==1){
            
            printf("\n#---------------------------------------------------#");
            printf("\n|    Nome do motorista: %s                          ",driver.nome);
            printf("\n|    Id do motorista: %d                            ",driver.driver_id);
            printf("\n|    Idade: %d                                      ",driver.idade);
            printf("\n|    Telefone: %d                                   ",driver.telefone);
            printf("\n#---------------------------------------------------#\n\n");
        }
    }
    fclose(m);
    getch();
}
void add_car(){ // função para adicionar carros
    carro car;
    FILE *c;
    c = fopen("carross.txt","ab");   
    
    if(c == NULL){
        printf("       [!]problemas na abertura do arquivo...");
    }else{
        do{
            system("cls");
            printf("\n  #-------------  Cadastro Carro  -----------------#");
            printf("\n  |                                                |");
            printf("\n  #------------------------------------------------#");
            
            fflush(stdin);
            printf("\n\n      >Insira o a marca do carro: ");
            gets(car.marca); 
            
            fflush(stdin);
            printf("\n\n      >Insira o modelo do carro: ");
            gets(car.modelo); 
            
            
            printf("\n\n      >Insira o id do carro: ");
            scanf("%d",&car.car_id);
            fwrite(&car, sizeof(carro), 1, c);
            
        
            
            printf("\n\n      [!]Deseja adicionar mais um motorista? (s/n)? ");
            
        }while(getche() == 's');
        fclose(c);
    }
    
}
 
void listar_car(){
    system("cls");
    carro car;
    FILE *c;
    c = fopen("carross.txt","rb");   
    
    if(c == NULL){
        printf("       [!]problemas na abertura do arquivo...");
    }else{
        while(fread(&car, sizeof(carro), 1, c)==1){
            
            printf("\n#---------------------------------------------------#");
            printf("\n|    Marca do Carro: %s                          ",car.marca);
            printf("\n|    Modelo do Carro: %s                            ",car.modelo);
            printf("\n|    ID do carro: %d                                      ",car.car_id);
            printf("\n#---------------------------------------------------#\n\n");
        }
    }
    fclose(c);
    getch();
}
 
void remove_driver(){ // função para remover motorisra
    system("cls");
    listar_driver();
    motorista driver;
    FILE *m, *temporario;
    m = fopen("motoristasss.txt","r+");   
    temporario = fopen("temp.txt","w");
    int id;
    printf("\n\n      >Insira o id do motorista que você deseja excluir : ");
    scanf("%d",&id);
    
    if(m == NULL){
        printf("       [!]problemas na abertura do arquivo...");
    }else{
        while(fread(&driver, sizeof(motorista), 1, m)==1){
            if(id != driver.driver_id){
                fwrite(&driver, sizeof(motorista), 1, temporario);
            }
            
            
        }
    }
    
    if(ferror(temporario)){
        printf("\n        [!]Erro ao excluir\n");
    }else{
        printf("\n-----------Excluído com sucesso!-------------");
    }
    
    fclose(temporario);
    fclose(m);
    remove("motoristasss.txt");
    rename("temp.txt", "motoristasss.txt");
    getch();
     
}
 
void remove_car(){ // função para remover carro
system("cls");
    listar_car();
    carro car;
    FILE *c, *temporario;
    c = fopen("caross.txt","r+");   
    temporario = fopen("temp.txt","w");
    
    int id;
    printf("\n\n      >Insira o id do carro que você deseja excluir : ");
    scanf("%d",&id);
    
    if(c == NULL){
        printf("       [!]problemas na abertura do arquivo...");
    }else{
        while(fread(&car, sizeof(carro), 1, c)==1){
            if(id != car.car_id){
                fwrite(&car, sizeof(carro), 1, temporario);
            }
            
            
        }
    }
    
    if(ferror(temporario)){
        printf("\n        [!]Erro ao excluir\n");
    }else{
        printf("\n-----------Excluído com sucesso!-------------");
    }
    
    fclose(temporario);
    fclose(c);
    remove("carross.txt");
    rename("temp.txt", "carross.txt");
    getch();
      
}
int main(int argc, char const *argv[]){
    setlocale(LC_ALL, "Portuguese");
    int cadastrar;
    do{
        system("cls");
        printf("\n  #-------------  Cadastro carro e motorista  -------------#");
        printf("\n  |                                                        |");
        printf("\n  |                    Menu principal                      |");
        printf("\n  |                                                        |"); 
        printf("\n  |      1- Cadastrar motorista                            |");
        printf("\n  |      2- Cadastrar carro                                |");
        printf("\n  |      3- Remover carro                                  |");
        printf("\n  |      4- Remover motorista                              |");
        printf("\n  |      5- Listar Motoristas                              |");
        printf("\n  |      6- Listar Carros                                  |");
        printf("\n  |      7- Sair                                           |");
        printf("\n  #--------------------------------------------------------#\n");
        printf("\n          >Escolha uma opção: ");
    scanf("%d",&cadastrar);
    
    switch(cadastrar){
        case 1:
            add_driver();
            getch();
            break;
            
        case 2:
            add_car();
            getch();
            break;
            
        case 3:
            remove_car();
            getch();
            break;
            
        case 4:
            remove_driver();
            getch();
            break;
        
        case 5:
            listar_driver();
            getch();
            break;
        
        case 6:
            listar_car();
            getch();
            break;
    }
 }while(cadastrar <= 6 && cadastrar !=0); // laço 
 
  
    return 0;
}
I’m not sure I understand, but you can create a
structwith a car and a driver– Júlio Evêncio
Use a database. Mysql 8.0 C API Developer Guide, Sqlite, Postgresql C Library
– Augusto Vasques
The problem seems to me is that the author of the question started writing code before he had a clear notion of how the system should work. It’s a software and data modeling problem. So adding a database will not only not solve the problem but will add an extra layer of complexity. As for the question itself, I think the author should clarify what his program should do, what are the requirements and business rules, and what features he wants to add with this relation car x driver.
– Vander Santos