Skip to content

Instantly share code, notes, and snippets.

@Igormandello
Created October 8, 2017 21:23
Show Gist options
  • Save Igormandello/93de0818707113609b092aee23541a4b to your computer and use it in GitHub Desktop.
Save Igormandello/93de0818707113609b092aee23541a4b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef
struct
{
char ra [9],
nome [41],
endereco [101],
cidade [31],
uf [3],
fone [11],
cel [11],
email [41];
unsigned int idade;
double cd;
} Aluno;
void incluirAluno (Aluno a, Aluno** v, int* t)
{
(*t)++;
Aluno* v2 = (Aluno*)malloc(*t * sizeof(Aluno));
if (*t == 1)
v2[0] = a;
else
{
int j = 0;
for (; j < *t - 1; j++)
{
if (strcmp(a.ra, (*v)[j].ra) < 0)
{
int n = *t - 1;
for (; n > j; n--)
v2[n] = (*v)[n - 1];
v2[n] = a;
break;
}
else
{
v2[j] = (*v)[j];
v2[j + 1] = a;
}
}
}
(*v) = v2;
}
int main()
{
int tamanho = 0;
Aluno* vet = (Aluno*)malloc(5 * sizeof(Aluno));
Aluno a;
strcpy(a.ra, "16179");
Aluno b;
strcpy(b.ra, "16181");
Aluno c;
strcpy(c.ra, "16180");
incluirAluno (a, &vet, &tamanho);
incluirAluno (b, &vet, &tamanho);
incluirAluno (c, &vet, &tamanho);
printf("%s\n%s\n%s", vet[0].ra, vet[1].ra, vet[2].ra);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment