Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Aluno{
- int matricula;
- struct Aluno * prox;
- };
- struct Aluno * novo, * lista, * ultimo, *elemento;
- void primeiro(int mat)
- {
- lista = malloc(sizeof(struct Aluno));
- lista -> matricula = mat;
- }
- void demais(int mat){
- novo = malloc(sizeof(struct Aluno));
- novo -> matricula = mat;
- ultimo = lista;
- while (ultimo -> prox != NULL){
- ultimo = ultimo -> prox;
- }
- ultimo -> prox = novo;
- }
- void listar(){
- printf("\n\nListando\n");
- ultimo = lista;
- while(ultimo != NULL){
- printf("%d\n", ultimo -> matricula);
- ultimo = ultimo -> prox;
- }
- }
- int main(int argc, char** argv) {
- int mat;
- while(1){
- scanf("%d", &mat);
- if (mat == 0){
- break;
- }
- if (lista == NULL){
- primeiro(mat);
- } else{
- demais(mat);
- }
- }
- listar();
- return (EXIT_SUCCESS);
- }
Add Comment
Please, Sign In to add comment