Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define SIZE 1009
- struct no {
- char matricula[6];
- struct no *next;
- };
- typedef struct no *TABELA[SIZE];
- int insert(Tabela t,int pos,char matricula[6]){
- struct no* auxn = malloc(sizeof(struct no));
- TABELA t = NULL;
- auxt=t;
- if(auxt){
- while(auxt[pos]){
- if(strcmp(auxt[pos]->matricula,matricula)==0)
- pos=-1;
- auxt[pos] = auxt[pos]->next;
- }
- if(pos!=-1)
- auxt[pos]->matricula = matricula;
- }
- else{
- auxt = calloc(sizeof(struct no),SIZE);
- auxt[pos] = malloc(sizeof(struct no));
- auxt[pos]->matricula = matricula;
- }
- return pos;
- }
- int main(){
- TABELA t = NULL;
- char matricula[6] = "BMW";
- int r = insert(t,1,matricula);
- printf("%d\n",r);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement