In my project I must create a program that has a menu where I have two options.
In the first "List all versions of a vehicle" in which I must enter who made it (toyota, suzuki, etc) and the name of the model, giving me as a result and in the second "Validate the manufactured vehicles", in this the model is written and the program must show the requested vehicle (if it exists) and in case it does not have to respond that there is no such model.
All vehicle information is in a .csv file For the time being I have this, I do not use well the structured no linked lists so I still do not know what to put them, if they could help me I would appreciate it a lot.
#include <stdio.h>
#include <string.h>
struct Datos_Vehiculos{
char Fabricante[],Modelo[],Tipo_Vehiculo[],Tipo_Combustible[],Tipo_Cambio[],Tipo_Traccion[];
int Year_Fabricacion,Numero_Cilindro;
float Desplazamiento_Litros;
};
int Buscar{
}
main(){
FILE *Autos;
Autos = fopen("vehiculos-diminuto.csv", "r");
fscanf(Autos,"%d",&nautos);
int opcion,nautos;
do{
printf("Bienvenido, elija una opcion. \n");
printf(" \n MENU \n");
printf("1. Listar Versiones de Vehiculo\n");
printf("2. Validar Vehiculo Fabricado\n");
printf("3. Salir\n");
printf(" Su opcion fue: ");
scanf("%d", & opcion);
fflush(stdin);
switch (opcion){
case 1: printf("Ingrese Fabricante y nombre del modelo: ");
scanf("%c %c",)
break;
case 2: printf(Ingrese el modelo que desea: );
}
}
}
What I have now is:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 50
#define LARGO 150
struct Marcas{
char *Marca;
struct Marcas *SgteMa;
};
struct Modelos{
char *Modelo;
struct Modelos *SgteMo;
};
struct Datos{
int Year;
char *Tipo;
float Desplazamiento;
int Cilindros;
char *Combustible;
char *Cambio;
char *Traccion;
struct Datos *SgteDs;
};
struct Marcas *Ingresar_Marca(struct Marcas *Inicio, char Dato[]){
struct Marcas *Nuevo;
Nuevo = malloc(sizeof(struct Marcas));
Nuevo -> Marca = Dato;
Nuevo -> SgteMa = Inicio;
return Nuevo;
}
struct Modelos *Ingresar_Modelo(struct Modelos *Inicio, char Dato[]){
struct Modelos *Nuevo;
Nuevo = malloc(sizeof(struct Modelos));
Nuevo -> Modelo = Dato;
Nuevo -> SgteMo = Inicio;
return Nuevo;
}
struct Datos *Ingresar_Datos(struct Datos *Comienzo, char Linea[], int Start)
{
struct Datos *Nuevo;
char Dato[MAX];
int Inicio = Start;
Nuevo = malloc(sizeof(struct Datos));
Nuevo -> SgteDs = Comienzo;
return Nuevo;
}
int PuntoComa(int Inicio, char Linea[], char Regreso[]){
int Largo, Num, Total, Cont, Final;
char Dato[MAX];
Largo = strlen(Linea);
for(Num = Inicio; Num < Largo; Num++){
if(Linea[Num] == ';' || Linea[Num+1] == '#include <stdio.h>
#include <string.h>
struct Datos_Vehiculos{
char Fabricante[],Modelo[],Tipo_Vehiculo[],Tipo_Combustible[],Tipo_Cambio[],Tipo_Traccion[];
int Year_Fabricacion,Numero_Cilindro;
float Desplazamiento_Litros;
};
int Buscar{
}
main(){
FILE *Autos;
Autos = fopen("vehiculos-diminuto.csv", "r");
fscanf(Autos,"%d",&nautos);
int opcion,nautos;
do{
printf("Bienvenido, elija una opcion. \n");
printf(" \n MENU \n");
printf("1. Listar Versiones de Vehiculo\n");
printf("2. Validar Vehiculo Fabricado\n");
printf("3. Salir\n");
printf(" Su opcion fue: ");
scanf("%d", & opcion);
fflush(stdin);
switch (opcion){
case 1: printf("Ingrese Fabricante y nombre del modelo: ");
scanf("%c %c",)
break;
case 2: printf(Ingrese el modelo que desea: );
}
}
}
'){
Final = Num;
Cont = 0;
for(Total = Inicio; Total < Final; Total++){
Dato[Cont] = Linea[Total];
Dato[Cont+1] = '#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 50
#define LARGO 150
struct Marcas{
char *Marca;
struct Marcas *SgteMa;
};
struct Modelos{
char *Modelo;
struct Modelos *SgteMo;
};
struct Datos{
int Year;
char *Tipo;
float Desplazamiento;
int Cilindros;
char *Combustible;
char *Cambio;
char *Traccion;
struct Datos *SgteDs;
};
struct Marcas *Ingresar_Marca(struct Marcas *Inicio, char Dato[]){
struct Marcas *Nuevo;
Nuevo = malloc(sizeof(struct Marcas));
Nuevo -> Marca = Dato;
Nuevo -> SgteMa = Inicio;
return Nuevo;
}
struct Modelos *Ingresar_Modelo(struct Modelos *Inicio, char Dato[]){
struct Modelos *Nuevo;
Nuevo = malloc(sizeof(struct Modelos));
Nuevo -> Modelo = Dato;
Nuevo -> SgteMo = Inicio;
return Nuevo;
}
struct Datos *Ingresar_Datos(struct Datos *Comienzo, char Linea[], int Start)
{
struct Datos *Nuevo;
char Dato[MAX];
int Inicio = Start;
Nuevo = malloc(sizeof(struct Datos));
Nuevo -> SgteDs = Comienzo;
return Nuevo;
}
int PuntoComa(int Inicio, char Linea[], char Regreso[]){
int Largo, Num, Total, Cont, Final;
char Dato[MAX];
Largo = strlen(Linea);
for(Num = Inicio; Num < Largo; Num++){
if(Linea[Num] == ';' || Linea[Num+1] == '%pre%'){
Final = Num;
Cont = 0;
for(Total = Inicio; Total < Final; Total++){
Dato[Cont] = Linea[Total];
Dato[Cont+1] = '%pre%';
Cont++;
}
strcpy(Regreso,Dato);
return Final+1;
}
}
}
main(){
int Inicio, ContPuntoComa;
char Linea[LARGO];
char Dato[MAX];
FILE *Vehiculos;
Vehiculos = fopen("vehiculos-chico.csv","r");
Inicio = 0;
struct Marcas *Marca;
Marca = NULL;
struct Modelos *Modelo;
Modelo = NULL;
struct Datos *AllDatos;
AllDatos = NULL;
while(fgets(Linea,LARGO,Vehiculos) != NULL){
Inicio = PuntoComa(Inicio,Linea,Dato);
Marca = Ingresar_Marca(Marca,Dato);
Inicio = PuntoComa(Inicio,Linea,Dato);
Modelo = Ingresar_Modelo(Modelo,Dato);
AllDatos = Ingresar_Datos(AllDatos,Linea,Inicio);
Inicio = 0;
}
}
';
Cont++;
}
strcpy(Regreso,Dato);
return Final+1;
}
}
}
main(){
int Inicio, ContPuntoComa;
char Linea[LARGO];
char Dato[MAX];
FILE *Vehiculos;
Vehiculos = fopen("vehiculos-chico.csv","r");
Inicio = 0;
struct Marcas *Marca;
Marca = NULL;
struct Modelos *Modelo;
Modelo = NULL;
struct Datos *AllDatos;
AllDatos = NULL;
while(fgets(Linea,LARGO,Vehiculos) != NULL){
Inicio = PuntoComa(Inicio,Linea,Dato);
Marca = Ingresar_Marca(Marca,Dato);
Inicio = PuntoComa(Inicio,Linea,Dato);
Modelo = Ingresar_Modelo(Modelo,Dato);
AllDatos = Ingresar_Datos(AllDatos,Linea,Inicio);
Inicio = 0;
}
}
But with this I have an error and that is that the brand is changed by the model and the data does not save anything: (