#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 12
typedef struct aluno {
char nome[ 40 ] ;
int idade;
} Aluno;
typedef struct lista {
size_t qnt;
Aluno dados[ MAX] ;
} Lista;
Lista* cria( ) {
Lista
* l
= malloc ( sizeof ( Lista
) ) ; if ( l != NULL)
l-> qnt = 0 ;
return l;
}
int insere( Lista * l, Aluno al) { //insere no inicio
if ( l == NULL)
return 0 ;
if ( l-> qnt == MAX)
return 0 ;
for ( int i = l-> qnt; i > 0 ; i-- ) {
l-> dados[ i] = l-> dados[ i - 1 ] ;
}
memcpy ( & l
-> dados
[ 0 ] , & al
, sizeof ( Aluno
) ) ; l-> qnt++;
return 1 ;
}
void liberar( Lista * l) {
}
void exibe( Lista * l) {
if ( l-> qnt == 0 ) {
printf ( "\n Lista esta vazia.\n \n " ) ; }
for ( int i = 0 ; i < l-> qnt; i++ ) {
printf ( "Aluno: %s" , l
-> dados
[ i
] .
nome ) ; printf ( ", de Idade: %d\n " , l
-> dados
[ i
] .
idade ) ; }
}
int main( ) {
Lista * l = cria( ) ;
Aluno al;
int opc;
do {
printf ( "\t Escolha uma Opcao\n " ) ; printf ( "1: Cadastrar Aluno\n " ) ; switch ( opc) {
case 0 :
break ;
case 1 : //inconsistĂȘncia
insere( l, al) ;
break ;
case 2 :
exibe( l) ;
break ;
default :
break ;
}
} while ( opc != 0 ) ;
liberar( l) ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKI2RlZmluZSBNQVggMTIKCnR5cGVkZWYgc3RydWN0IGFsdW5vIHsKICAgIGNoYXIgbm9tZVs0MF07CiAgICBpbnQgaWRhZGU7Cn0gQWx1bm87Cgp0eXBlZGVmIHN0cnVjdCBsaXN0YSB7CiAgICBzaXplX3QgcW50OwogICAgQWx1bm8gZGFkb3NbTUFYXTsKfSBMaXN0YTsKCkxpc3RhKiBjcmlhKCkgewogICAgTGlzd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gkgICAgcHJpbnRmKCIyOiBFeGliaXIgQWx1bm9zXG4iKTsKCSAgICBwcmludGYoIk9wY2FvOiAiKTsKCSAgICBzY2FuZigiJWQiLCAmb3BjKTsKCSAgICBzd2l0Y2gob3BjKSB7CgkgICAgY2FzZSAwOgoJICAgICAgICBicmVhazsKCSAgICBjYXNlIDE6IC8vaW5jb25zaXN0w6puY2lhCgkgICAgICAgIHByaW50ZigiXG5EaWdpdGUgbyBub21lOiAiKTsKCSAgICAgICAgc2NhbmYoIiVzIiwgYWwubm9tZSk7CgkgICAgICAgIHByaW50ZigiRGlnaXRlIGEgaWRhZGU6ICIpOwoJICAgICAgICBzY2FuZigiJWQiLCAmYWwuaWRhZGUpOwoJICAgICAgICBpbnNlcmUobCwgYWwpOwoJICAgICAgICBzeXN0ZW0oImNscyIpOwoJICAgICAgICBicmVhazsKCSAgICBjYXNlIDI6CgkgICAgICAgIGV4aWJlKGwpOwoJICAgICAgICBicmVhazsKCSAgICBkZWZhdWx0OgoJICAgICAgICBwcmludGYoIk9wY2FvIEludmFsaWRhLlxuIik7CgkgICAgICAgIGJyZWFrOwoJICAgIH0KICAgIH0gd2hpbGUgKG9wYyAhPSAwKTsKICAgIGxpYmVyYXIobCk7Cn0=
stdout
Escolha uma Opcao
O: sair
1: Cadastrar Aluno
2: Exibir Alunos
Opcao:
Digite o nome: Digite a idade: Escolha uma Opcao
O: sair
1: Cadastrar Aluno
2: Exibir Alunos
Opcao:
Digite o nome: Digite a idade: Escolha uma Opcao
O: sair
1: Cadastrar Aluno
2: Exibir Alunos
Opcao:
Digite o nome: Digite a idade: Escolha uma Opcao
O: sair
1: Cadastrar Aluno
2: Exibir Alunos
Opcao: Aluno: maria, de Idade: 30
Aluno: jose, de Idade: 20
Aluno: joao, de Idade: 10
Escolha uma Opcao
O: sair
1: Cadastrar Aluno
2: Exibir Alunos
Opcao:
stderr
sh: 1: cls: not found
sh: 1: cls: not found
sh: 1: cls: not found