Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define SIZE 1009
  6.  
  7. struct no {
  8.     char matricula[6];
  9.     struct no *next;
  10. };
  11.  
  12. typedef struct no *TABELA[SIZE];
  13.  
  14. int insert(Tabela t,int pos,char matricula[6]){
  15.     struct no* auxn = malloc(sizeof(struct no));
  16.     TABELA t = NULL;
  17.     auxt=t;
  18.  
  19.     if(auxt){
  20.         while(auxt[pos]){
  21.             if(strcmp(auxt[pos]->matricula,matricula)==0)
  22.                 pos=-1;
  23.             auxt[pos] = auxt[pos]->next;
  24.         }
  25.         if(pos!=-1)
  26.             auxt[pos]->matricula = matricula;
  27.     }
  28.     else{
  29.         auxt = calloc(sizeof(struct no),SIZE);
  30.         auxt[pos] = malloc(sizeof(struct no));
  31.         auxt[pos]->matricula = matricula;
  32.     }
  33.     return pos;
  34. }
  35.  
  36. int main(){
  37.     TABELA t = NULL;
  38.     char matricula[6] = "BMW";
  39.     int r = insert(t,1,matricula);
  40.     printf("%d\n",r);
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement