Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio2.h>
- #include<stdlib.h>
- #include<conio.h>
- #include<string.h>
- #include<ctype.h>
- struct TpAluno
- {
- char nome[50];
- char RA[10];
- };
- struct TpDis
- {
- char codDis[10];
- char materia[50];
- };
- struct DisAll
- {
- }
- int Busca(FILE *arq, char chave[10])
- {
- TpDis RegDis;
- fseek (arq, 0, 0);//rewind(arq);
- fread(&RegDis, sizeof(TpDis), 1, arq);
- while(!feof(arq)&&strcmp(chave, RegDis.codDis)!=0)
- {
- fread(&RegDis, sizeof(TpDis), 1, arq);
- }
- if(strcmp(chave, RegDis.codDis)==0)
- {
- return ftell(arq)-sizeof(TpDis);
- }
- else
- return -1;
- }
- int buscaAluno(FILE *arq, char chave[10])
- {
- TpAluno RegRA;
- fseek(arq, 0, 0);
- fread(&RegRA, sizeof (TpAluno), 1, arq);
- while(!feof(arq)&&strcmp(chave, RegRA.RA)!=0)
- {
- fread(&RegRA, sizeof(TpAluno), 1, arq);
- }
- if(strcmp(chave, RegRA.RA)==0)
- {
- return ftell(arq)-sizeof (TpAluno);
- }
- else
- return -1;
- }
- void cadDis(FILE *arq)
- { TpDis reg;
- arq=fopen("Disp.dat", "ab+");
- printf("Cadastro de Disciplinas:\n");
- printf("Digite o Codigo:\n");
- fflush(stdin);
- gets(reg.codDis);
- while(strcmp(reg.codDis,"\0")!=0)
- {
- int p=Busca(arq, reg.codDis );
- if(p==-1)
- {
- printf("Nome da Disciplina:");
- fflush(stdin);
- gets(reg.materia);
- }
- else
- printf("Disciplina ja Cadastrada!!!\n");
- fwrite(®,sizeof(TpDis),1, arq);
- printf("Digite o Codido:\n");
- fflush(stdin);
- gets(reg.codDis);
- }
- fclose(arq);
- //rb rb ab+
- }
- void cadAluno(FILE *arq)
- { TpAluno reg;
- arq=fopen("Alunos.dat", "ab+");
- printf("Cadastro de Alunos:\n");
- printf("Digite o RA:\n");
- fflush(stdin);
- gets(reg.RA);
- while(strcmp(reg.RA,"\0")!=0)
- {
- int p=buscaAluno(arq, reg.RA);
- if(p==-1)
- {
- printf("Digite o nome:");
- fflush(stdin);
- gets(reg.nome);
- }
- else
- printf("Aluno ja Cadastrado!!!\n");
- fwrite(®,sizeof(TpAluno),1, arq);
- printf("Digite o RA:\n");
- fflush(stdin);
- gets(reg.RA);
- }
- fclose(arq);
- //rb rb ab+
- }
- int main(void)
- {
- FILE *Parq;
- cadDis(Parq);
- cadAluno(Parq);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement