Enviado em 11/06/2024 - 00:49h
tenho a seguinte função em C99 para uma agenda usando estrutura binaria:
void changeContact(PhoneBook **root, char *str)
{
if ((*root) != NULL)
{
if (strcasecmp((*root)->name, str) > 0)
{
changeContact(&(*root)->left, str);
}
else
{
if (strcasecmp((*root)->name, str) < 0)
{
changeContact(&(*root)->right, str);
}
else
{
if (strcmp((*root)->name, str) == 0)
{
int phone;
message6();
printf("\n\tNAME: %s", (*root)->name);
scanf(" %20[^\n]s", (*root)->name);
printf("\n\tNEW PHONE: ");
scanf(" %d", &phone);
(*root)->phone = phone;
message7();
}
}
}
}
else
{
message8();
}
}
void changeContact(PhoneBook **root, char *str)
{
int new_phone;
char new_name[20];
if ((*root) != NULL)
{
if (strcasecmp((*root)->name, str) > 0)
{
changeContact(&(*root)->left, str);
}
else
{
if (strcasecmp((*root)->name, str) < 0)
{
changeContact(&(*root)->right, str);
}
else
{
if (strcmp((*root)->name, str) == 0)
{
int choice;
message6();
printf("\n\tCURRENT NAME: %s", (*root)->name);
printf("\n\tCURRENT PHONE: %d", (*root)->phone);
printf("\n\n\tDo you want to change the name or phone?\n\tEnter (1-Name, 2-Phone, 0-Cancel): ");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("\n\tNEW NAME: ");
scanf("%20[^\n]s", new_name);
strcpy((*root)->name, new_name);
//(*root)->name = new_name;
message7();
break;
case 2:
printf("\n\tNEW PHONE: ");
scanf("%d", &new_phone);
strcpy((*root)->phone, new_phone);
//(*root)->phone = new_phone;
message7();
break;
default: printf("\n\tNO CHANGES.\n");
}
}
}
}
}
else
{
message8();
}
}
strcpy((*root)->name, new_name);
(*root)->name = new_name;
strcpy((*root)->phone, new_phone);
(*root)->phone = new_phone;
Compilando um Kernel customizado a partir do código-fonte do Kernel do Debian 12
Gentoo binário ao lado da sua distro atual
Documentação para a função de carregamento saudável da bateria do notebook Acer Aspire 5 no Linux
Instalando Google Chrome no Linux Mint 22
O Que Fazer Após Instalar Linux Mint 22
Instalando o Dolphin e deixando-o "pretinho" acompanhando o tema escuro do Gnome-Shell