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;
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Atualizar Debian Online de uma Versão para outra
Instalar driver Nvidia no Debian 13
Redimensionando, espelhando, convertendo e rotacionando imagens com script
Debian 13 Trixie para Iniciantes
Convertendo pacotes DEB que usam ZSTD (Padrão Novo) para XZ (Padrão Antigo)