
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;
Como atualizar sua versão estável do Debian
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Script de montagem de chroot automatica
Atualizar Linux Mint 22.2 para 22.3 beta
Jogar games da Battle.net no Linux com Faugus Launcher
Como fazer a Instalação de aplicativos para acesso remoto ao Linux
Instalar Dual Boot, Linux+Windows. (5)
Conky, alerta de temperatura alta (16)
De volta para o futuro - ou melhor, para o presente (parte 2) (3)









