Guest User

Untitled

a guest
Nov 19th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. struct Datos {
  5.  
  6. int registrados;
  7. char Nombre[20];
  8. char GrupoSanguineo[5];
  9. char Sexo[25];
  10. int ML;
  11. int Edad;
  12. float Peso;
  13. };
  14. struct Datos Donantes[100];
  15. void Donar(){
  16.  
  17.  
  18.  
  19. int indice;
  20. for (indice=0;indice<(sizeof(Donantes))/ (sizeof (Donantes[0]));indice++){
  21.  
  22. if(Donantes[indice].registrados==0){
  23.  
  24. fflush(stdin);
  25. printf("Nombre y apellido del donante #%d: ",(indice+1));
  26. fgets(Donantes[indice].Nombre,20,stdin);
  27.  
  28. fflush(stdin);
  29. printf("Sexo: ");
  30. fgets(Donantes[indice].Sexo,25,stdin);
  31.  
  32. printf("Edad del Donante: ");
  33. scanf("%d",&Donantes[indice].Edad);
  34.  
  35. printf("Peso kg: ");
  36. scanf("%f",&Donantes[indice].Peso);
  37.  
  38. fflush(stdin);
  39. printf("Grupos sanguineos: ");
  40. fgets(Donantes[indice].GrupoSanguineo,5,stdin);
  41.  
  42. printf("ML a donar: ");
  43. scanf("%d",&Donantes[indice].ML);
  44.  
  45.  
  46. Donantes[indice].registrados=1;
  47. system("cls");
  48.  
  49. printf ("\n\nAlmacenado correctamente en Banco_De_Sangre.txt\n ");
  50.  
  51. FILE *Insertar = fopen("Banco_De_Sangre.txt","w+");
  52.  
  53.  
  54. fprintf(Insertar, "\t\tRegistro Exitoso\n");
  55. fprintf(Insertar, "\n%s",Donantes[indice].Nombre);
  56. fprintf(Insertar, "\n%s",Donantes[indice].Sexo);
  57. fprintf(Insertar, "\n%d",Donantes[indice].Edad);
  58. fprintf(Insertar, "\n%f",Donantes[indice].Peso);
  59. fprintf(Insertar, "\n%s",Donantes[indice].GrupoSanguineo);
  60. fprintf(Insertar, "\n%d",Donantes[indice].ML);
  61.  
  62. fclose(Insertar);
  63. system("PAUSE");
  64. break;
  65. }
  66. }
  67. }
  68.  
  69.  
  70. void Lista(){
  71. system("cls");
  72.  
  73. FILE *Insertar;
  74. Insertar = fopen("Banco_De_Sangre.txt","r");
  75. char c;
  76. printf("\n");
  77.  
  78. //extraccion de datos con el feof y () la funcion
  79. while(feof(Insertar)==0){
  80.  
  81. //getc retorno del carácter siguiente Si ocurre un error de lectura con getc
  82. c=getc(Insertar);
  83. (c);
  84. }
  85. putchar('\n');
  86. fclose(Insertar);
  87. printf("\n\n");
  88. }
  89.  
  90.  
  91.  
  92.  
  93. /*void Busqueda(){
  94. int j;
  95. int ID= 0;
  96.  
  97. for(j=0; j < (sizeof(Donantes))/(sizeof(Donantes[0]));j++){
  98. if(Donantes[j].registrados==1){
  99.  
  100.  
  101. /*printf("%d. %s\t\n",(j+1),Donantes[j].Nombre);
  102. printf("ID Usuario: ");
  103. scanf("%d",&ID);
  104.  
  105. system("cls");
  106. fflush(stdin);
  107.  
  108. printf("%s\n",Donantes[ID-1].Nombre);
  109. printf("Sexo: %s\n",Donantes[ID-1].Sexo);
  110. printf("Edad %d\n",Donantes[ID-1].Edad);
  111. printf("Peso kg: %.2f\n",Donantes[ID-1].Peso);
  112. printf("Grupo sanguineo: %s\n",Donantes[ID-1].GrupoSanguineo);
  113. printf("Donado: %dML\n",Donantes[ID-1].ML);
  114. printf("\n\n");
  115.  
  116. }
  117. }
  118. }
  119. */
  120. int main(){
  121.  
  122. int Menu=0;
  123. printf("\t\t\t\t>>>Banco de sangre<<<\n\n");
  124.  
  125. do{
  126.  
  127. printf("Registrar donantes(1)\n");
  128. printf("Lista de donantes(2)\n");
  129. printf("Busqueda de donantes(3)\n");
  130. printf("Salir(4)\n");
  131. scanf("%d",&Menu);
  132.  
  133. switch(Menu){
  134.  
  135.  
  136. case 1: {
  137. Donar();
  138. break;
  139. }
  140.  
  141. case 2:
  142. {
  143. if (Insertar==NULL)
  144. {
  145. fclose(Insertar);
  146. printf ("\nAun no se ha registrado un usuarios\n\n");
  147.  
  148. }
  149.  
  150. else
  151. {
  152. fclose(Insertar);
  153. Lista();
  154.  
  155. }
  156. break;
  157. }
  158.  
  159. case 3:
  160. {
  161. void Busqueda();
  162. Busqueda();
  163. break;
  164. }
  165.  
  166. }
  167. }while(Menu !=4);
  168.  
  169.  
  170. return 0;
  171. }
Advertisement
Add Comment
Please, Sign In to add comment