Advertisement
rrcfs

exercici

Oct 31st, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio2.h>
  3. #include<stdlib.h>
  4. #include<conio.h>
  5. #include<string.h>
  6. #include<ctype.h>
  7. struct TpAluno
  8. {
  9. char nome[50];
  10. char RA[10];
  11. };
  12. struct TpDis
  13. {
  14. char codDis[10];
  15. char materia[50];
  16. };
  17. struct DisAll
  18. {
  19.  
  20.  
  21.  
  22.  
  23. }
  24. int Busca(FILE *arq, char chave[10])
  25. {
  26.  
  27. TpDis RegDis;
  28. fseek (arq, 0, 0);//rewind(arq);
  29. fread(&RegDis, sizeof(TpDis), 1, arq);
  30. while(!feof(arq)&&strcmp(chave, RegDis.codDis)!=0)
  31. {
  32. fread(&RegDis, sizeof(TpDis), 1, arq);
  33. }
  34. if(strcmp(chave, RegDis.codDis)==0)
  35. {
  36. return ftell(arq)-sizeof(TpDis);
  37. }
  38. else
  39. return -1;
  40. }
  41. int buscaAluno(FILE *arq, char chave[10])
  42. {
  43. TpAluno RegRA;
  44. fseek(arq, 0, 0);
  45. fread(&RegRA, sizeof (TpAluno), 1, arq);
  46. while(!feof(arq)&&strcmp(chave, RegRA.RA)!=0)
  47. {
  48. fread(&RegRA, sizeof(TpAluno), 1, arq);
  49. }
  50. if(strcmp(chave, RegRA.RA)==0)
  51. {
  52. return ftell(arq)-sizeof (TpAluno);
  53. }
  54. else
  55. return -1;
  56. }
  57.  
  58. void cadDis(FILE *arq)
  59. { TpDis reg;
  60. arq=fopen("Disp.dat", "ab+");
  61. printf("Cadastro de Disciplinas:\n");
  62. printf("Digite o Codigo:\n");
  63. fflush(stdin);
  64. gets(reg.codDis);
  65. while(strcmp(reg.codDis,"\0")!=0)
  66. {
  67. int p=Busca(arq, reg.codDis );
  68. if(p==-1)
  69. {
  70. printf("Nome da Disciplina:");
  71. fflush(stdin);
  72. gets(reg.materia);
  73. }
  74. else
  75. printf("Disciplina ja Cadastrada!!!\n");
  76. fwrite(&reg,sizeof(TpDis),1, arq);
  77. printf("Digite o Codido:\n");
  78. fflush(stdin);
  79. gets(reg.codDis);
  80. }
  81. fclose(arq);
  82. //rb rb ab+
  83. }
  84. void cadAluno(FILE *arq)
  85. { TpAluno reg;
  86. arq=fopen("Alunos.dat", "ab+");
  87. printf("Cadastro de Alunos:\n");
  88. printf("Digite o RA:\n");
  89. fflush(stdin);
  90. gets(reg.RA);
  91. while(strcmp(reg.RA,"\0")!=0)
  92. {
  93. int p=buscaAluno(arq, reg.RA);
  94. if(p==-1)
  95. {
  96. printf("Digite o nome:");
  97. fflush(stdin);
  98. gets(reg.nome);
  99. }
  100. else
  101. printf("Aluno ja Cadastrado!!!\n");
  102. fwrite(&reg,sizeof(TpAluno),1, arq);
  103. printf("Digite o RA:\n");
  104. fflush(stdin);
  105. gets(reg.RA);
  106. }
  107. fclose(arq);
  108. //rb rb ab+
  109. }
  110. int main(void)
  111. {
  112. FILE *Parq;
  113. cadDis(Parq);
  114. cadAluno(Parq);
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement