
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
Quer auto-organizar janelas (tiling) no seu Linux? Veja como no Plasma 6 e no Gnome
Copiando caminho atual do terminal direto para o clipboard do teclado
Script de montagem de chroot automatica
Instalar Dual Boot, Linux+Windows. (9)
Eaí? Já programou no windows? (2)
Erro ao enviar arquivos para o Storage Synology NAS (0)
Conky, alerta de temperatura alta (17)
De volta para o futuro - ou melhor, para o presente (parte 2) (3)









