#include<stdio.h>
#include<stdlib.h>
////// ORIGINALMENTE AS FUNÇÕES ESTÃO EM ARQUIVOS SEPARADOS
// DECLARAÇÃO DA STRUCT A SER EXPLORADA
typedef struct registro_agenda{
char * name;
char * adress;
int * phone;
struct registro_agenda * next;
} registro;
// FUNÇÃO PARA ALOCAR MEMÓRIA PARA UM TIPO "REGISTRO",
// OBSERVE QUE ELA TEM RETORNO "VOID" PROPOSITALMENTE E
// COMO ARGUMENTO RECEBE O ENDEREÇO DE UM PONTEIRO DO TIPO "REGISTRO"
void aloca_registro( registro ** ptr_registro, int len_name, int len_adress) {
* ptr_registro
= ( registro
* ) malloc ( sizeof ( registro
) ) ; * ptr_registro
-> name
= ( char * ) malloc ( len_name
* sizeof ( char ) ) ; * ptr_registro
-> adress
= ( char * ) malloc ( len_adress
* sizeof ( char ) ) ; * ptr_registro
-> phone
= ( int * ) malloc ( sizeof ( int ) ) ; * ptr_registro-> next = NULL;
}
// FUNÇÃO PARA PREENCHIMENTO DE UM TIPO "REGISTRO"
preencher_registro( registro ** ptr_registro) {
int yes= 1 ;
while ( yes) {
printf ( "\n \t DIGITE O NOME: " ) ; scanf ( "%s" ,** ptr_registro
-> nome
) ;
printf ( "\n \t DIGITE O ENDERECO: " ) ; scanf ( "%s" ,** ptr_registro
-> adress
) ;
printf ( "\n \t DIGITE O TELEFONE: " ) ; scanf ( "%i" ,** ptr_registro
-> phone
) ;
printf ( "GOSTARIA DE COLOCAR MAIS UM CONTATO NA AGENDA?" ) ; printf ( "\n \t 0 - NAO\n \t 1 - SIM" ) ;
if ( yes == 1 ) {
* ptr_registro = * ptr_registro-> next;
aloca_registro( ** ptr_registro, 30 , 50 ) ;
continue ;
}
else break ;
}
}
// FUNÇÃO PARA MOSTRAR UMA AGENDA NO CONSOLE
mostrar_agenda( registro ** ptr_registro) {
int reg= 1 ;
while ( * ptr_registro != NULL) {
printf ( "MOSTRANDO REGISTRO %i" , reg
++ ) ; printf ( "\t NOME %s\n " , ** ptr_registro
-> name
) ; printf ( "\t ENDERECO %s\n " , ** ptr_registro
-> adress
) ; printf ( "\t TELEFONE %i\n " , ** ptr_registro
-> phone
) ; printf ( "----------------------------------------------------------------\n \n " ) ; * ptr_registro = * ptr_registro-> next;
}
}
int main( ) {
registro * agenda= NULL;
printf ( "Teste de ponteiros para ponteiros, structs com ponteiros e funções com esses tipos de dados\n " ) ;
aloca_registro( & agenda, 30 , 50 ) ;
preencher_registro( & agenda) ;
mostrar_agenda( & agenda) ;
return 0 ;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+Ci8vLy8vLyBPUklHSU5BTE1FTlRFIEFTIEZVTsOHw5VFUyBFU1TDg08gRU0gQVJRVUlWT1MgU0VQQVJBRE9TCgovLyBERUNMQVJBw4fDg08gREEgU1RSVUNUIEEgU0VSIEVYUExPUkFEQQp0eXBlZGVmIHN0cnVjdCByZWdpc3Ryb19hZ2VuZGF7CgljaGFyICpuYW1lOwoJY2hhciAqYWRyZXNzOwoJaW50ICpwaG9uZTsKCXN0cnVjdCByZWdpc3Ryb19hZ2VuZGEgKm5leHQ7Cgl9IHJlZ2lzdHJvOwoKLy8gRlVOw4fDg08gUEFSQSBBTE9DQVIgTUVNw5NSSUEgUEFSQSBVTSBUSVBPICJSRUdJU1RSTyIsIAovLyBPQlNFUlZFIFFVRSBFTEEgVEVNIFJFVE9STk8gIlZPSUQiIFBST1BPU0lUQUxNRU5URSBFIAovLyBDT01PIEFSR1VNRU5UTyBSRUNFQkUgTyBFTkRFUkXDh08gREUgVU0gUE9OVEVJUk8gRE8gVElQTyAiUkVHSVNUUk8iCnZvaWQgYWxvY2FfcmVnaXN0cm8ocmVnaXN0cm8gKipwdHJfcmVnaXN0cm8sIGludCBsZW5fbmFtZSwgaW50IGxlbl9hZHJlc3MpewoKCSpwdHJfcmVnaXN0cm8gPSAocmVnaXN0cm8gKiltYWxsb2Moc2l6ZW9mKHJlZ2lzdHJvKSk7CgkqcHRyX3JlZ2lz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JyZWFrOwoJCX0KCQoJfQkKCi8vIEZVTsOHw4NPIFBBUkEgTU9TVFJBUiBVTUEgQUdFTkRBIE5PIENPTlNPTEUKbW9zdHJhcl9hZ2VuZGEocmVnaXN0cm8gKipwdHJfcmVnaXN0cm8pewoJaW50IHJlZz0xOwoJd2hpbGUoKnB0cl9yZWdpc3RybyAhPSBOVUxMKXsKCQlwcmludGYoIk1PU1RSQU5ETyBSRUdJU1RSTyAlaSIsIHJlZysrKTsKCQlwcmludGYoIlx0Tk9NRSAlc1xuIiwgKipwdHJfcmVnaXN0cm8tPm5hbWUpOwoJCXByaW50ZigiXHRFTkRFUkVDTyAlc1xuIiwgKipwdHJfcmVnaXN0cm8tPmFkcmVzcyk7CgkJcHJpbnRmKCJcdFRFTEVGT05FICVpXG4iLCAqKnB0cl9yZWdpc3Ryby0+cGhvbmUpOwoJCXByaW50ZigiLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLVxuXG4iKTsKCQkqcHRyX3JlZ2lzdHJvID0gKnB0cl9yZWdpc3Ryby0+bmV4dDsKCX0KCQoKCX0KCmludCBtYWluKCl7CglyZWdpc3RybyAqYWdlbmRhPU5VTEw7CglwcmludGYoIlRlc3RlIGRlIHBvbnRlaXJvcyBwYXJhIHBvbnRlaXJvcywgc3RydWN0cyBjb20gcG9udGVpcm9zIGUgZnVuw6fDtWVzIGNvbSBlc3NlcyB0aXBvcyBkZSBkYWRvc1xuIik7CgkKCWFsb2NhX3JlZ2lzdHJvKCZhZ2VuZGEsMzAsNTApOwoJcHJlZW5jaGVyX3JlZ2lzdHJvKCZhZ2VuZGEpOwoJbW9zdHJhcl9hZ2VuZGEoJmFnZW5kYSk7CglyZXR1cm4gMDsKfQ==
compilation info
prog.c: In function ‘aloca_registro’:
prog.c:19: error: request for member ‘name’ in something not a structure or union
prog.c:20: error: request for member ‘adress’ in something not a structure or union
prog.c:21: error: request for member ‘phone’ in something not a structure or union
prog.c:22: error: request for member ‘next’ in something not a structure or union
prog.c: At top level:
prog.c:27: warning: return type defaults to ‘int’
prog.c: In function ‘preencher_registro’:
prog.c:31: error: request for member ‘nome’ in something not a structure or union
prog.c:34: error: request for member ‘adress’ in something not a structure or union
prog.c:37: error: request for member ‘phone’ in something not a structure or union
prog.c:44: error: request for member ‘next’ in something not a structure or union
prog.c:45: error: incompatible type for argument 1 of ‘aloca_registro’
prog.c:41: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
prog.c: At top level:
prog.c:54: warning: return type defaults to ‘int’
prog.c: In function ‘mostrar_agenda’:
prog.c:58: error: request for member ‘name’ in something not a structure or union
prog.c:59: error: request for member ‘adress’ in something not a structure or union
prog.c:60: error: request for member ‘phone’ in something not a structure or union
prog.c:62: error: request for member ‘next’ in something not a structure or union
stdout