1
Good night people, all right? I’m developing this algorithm and I’m having a hard time deleting names I’ve registered, I don’t have advanced C skills, and I don’t know if the way I did the code is right or 100% optimized, but it’s working, accepted all kinds of tips and instructions for study of a particular topic, thank you.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int choice,gen;
int i;
char nomes[25][25];
char name[50][50];
char voider;
int main(){
void menu(void);
for(int x = 0; x <= 25; x++)
for(int j = 0; j < 1; j++)
nomes[x][j]='-';
menu();
return 0;
}
void menu(void){
void cadastro(void);
void pesquisa(void);
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/-----------------------G A T H E R E R V2.0 --------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n\nPress enter to continue...");
gets(&voider);
system("cls");
printf("\n/----------------------------------------------------------------------/");
printf("\n/-----------------------M A I N M E N U -----------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/---1 - REGISTER PEOPLE ===============================================/");
printf("\n/---2 - SEARCH PEOPLE =================================================/");
printf("\n/---3 - SHOW REGISTER =================================================/");
printf("\n/---4 - EXCLUDE PEOPLE ================================================/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/---Select a option----------------------------------------------------/\n");
scanf("%d",&choice);
fflush(stdin);
switch (choice){
case 1:
system("cls");
cadastro();
break;
case 2:
system("cls");
pesquisa();
break;
case 3:
system("cls");
imprimi();
break;
case 4:
system("cls");
excluir();
break;
}
}
void cadastro(void){
int g;
g = 0;
while(g == 0){
for(int x = 0; x <= 25; x++)
for(int j = 0; j < 25; j++)
if(strcmp(&nomes[x][j], "-") == 0){
printf("\n/----------------------------------------------------------------------/");
printf("\n/---------------------------REGISTER PEOPLE----------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/-----Enter a name or press 1 to leave to menu ------------------------/\n");
scanf("%s", &nomes[x]);
system("cls");
if(strcmp(&nomes[x], "1") == 0){
if(strcmp(&nomes[x], "1") == 0){
nomes[x][j] = '-';
}
menu();
}
}
}
}
void pesquisa(void){
void menu(void);
printf("\n/----------------------------------------------------------------------/");
printf("\n/---------------------------SEARCH PEOPLE -----------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/--------- Enter the name to search in database: ----------------------/\n");
fflush(stdin);
gets(name);
for(i = 0; i<= 25 ;i++){
if(strcmp(&nomes[i],name[0]) == 0){
system("cls");
printf("\n/----------------------------------------------------------------------/");
printf("\n/---------------------------SEARCH PEOPLE -----------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/---------The following name has been found: %s ",nomes[i]);
}
}
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/---1 -SEARCH AGAIN ===================================================/");
printf("\n/---2 -GOTO MENU ======================================================/\n");
scanf("%d",&gen);
if(gen == 1){
system("cls");
pesquisa();
}
if(gen == 2){
system("cls");
menu();
}
}
void imprimi(void){
printf("\n/----------------------------------------------------------------------/");
printf("\n/---------------------------REGISTER LIST------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
for(i = 0;i <=25;i++){
printf("\nNome encontrado: %s",nomes[i]);
}
printf("\n1 - GOTO MENU\n");
scanf("%d",&choice);
if(choice == 1);
menu();
}
void excluir(void){
printf("\n/----------------------------------------------------------------------/");
printf("\n/---------------------------EXCLUDE PEOPLE-----------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----Enter a name to exclude: \n");
fflush(stdin);
gets(name);
// Aqui eu insiro a comparação que irá trocar o "name" por um "-", simbolizando vazio quando eu entrar no menu "register list".
system("cls");
printf("\n/----------------------------------------------------------------------/");
printf("\n/---------------------------EXCLUDE PEOPLE ----------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/---------The following name has been excluded: ");
printf("\n/----------------------------------------------------------------------/");
printf("\n/----------------------------------------------------------------------/");
printf("\n/---1 -EXCLUDE AGAIN ==================================================/");
printf("\n/---2 -GOTO MENU ======================================================/\n");
scanf("%d",&gen);
if(gen == 1){
system("cls");
excluir();
}
if(gen == 2){
system("cls");
menu();
}
}
Inside the "delete" function, I’m having trouble trying to compare the "name" I get with the names that were stored in the "names" array, I can make the comparison "work" however, I can only replace only the first character, being for example "Lucas" to "-ucas".