Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- struct Datos {
- int registrados;
- char Nombre[20];
- char GrupoSanguineo[5];
- char Sexo[25];
- int ML;
- int Edad;
- float Peso;
- };
- struct Datos Donantes[100];
- void Donar(){
- int indice;
- for (indice=0;indice<(sizeof(Donantes))/ (sizeof (Donantes[0]));indice++){
- if(Donantes[indice].registrados==0){
- fflush(stdin);
- printf("Nombre y apellido del donante #%d: ",(indice+1));
- fgets(Donantes[indice].Nombre,20,stdin);
- fflush(stdin);
- printf("Sexo: ");
- fgets(Donantes[indice].Sexo,25,stdin);
- printf("Edad del Donante: ");
- scanf("%d",&Donantes[indice].Edad);
- printf("Peso kg: ");
- scanf("%f",&Donantes[indice].Peso);
- fflush(stdin);
- printf("Grupos sanguineos: ");
- fgets(Donantes[indice].GrupoSanguineo,5,stdin);
- printf("ML a donar: ");
- scanf("%d",&Donantes[indice].ML);
- Donantes[indice].registrados=1;
- system("cls");
- printf ("\n\nAlmacenado correctamente en Banco_De_Sangre.txt\n ");
- FILE *Insertar = fopen("Banco_De_Sangre.txt","w+");
- fprintf(Insertar, "\t\tRegistro Exitoso\n");
- fprintf(Insertar, "\n%s",Donantes[indice].Nombre);
- fprintf(Insertar, "\n%s",Donantes[indice].Sexo);
- fprintf(Insertar, "\n%d",Donantes[indice].Edad);
- fprintf(Insertar, "\n%f",Donantes[indice].Peso);
- fprintf(Insertar, "\n%s",Donantes[indice].GrupoSanguineo);
- fprintf(Insertar, "\n%d",Donantes[indice].ML);
- fclose(Insertar);
- system("PAUSE");
- break;
- }
- }
- }
- void Lista(){
- system("cls");
- FILE *Insertar;
- Insertar = fopen("Banco_De_Sangre.txt","r");
- char c;
- printf("\n");
- //extraccion de datos con el feof y () la funcion
- while(feof(Insertar)==0){
- //getc retorno del carácter siguiente Si ocurre un error de lectura con getc
- c=getc(Insertar);
- (c);
- }
- putchar('\n');
- fclose(Insertar);
- printf("\n\n");
- }
- /*void Busqueda(){
- int j;
- int ID= 0;
- for(j=0; j < (sizeof(Donantes))/(sizeof(Donantes[0]));j++){
- if(Donantes[j].registrados==1){
- /*printf("%d. %s\t\n",(j+1),Donantes[j].Nombre);
- printf("ID Usuario: ");
- scanf("%d",&ID);
- system("cls");
- fflush(stdin);
- printf("%s\n",Donantes[ID-1].Nombre);
- printf("Sexo: %s\n",Donantes[ID-1].Sexo);
- printf("Edad %d\n",Donantes[ID-1].Edad);
- printf("Peso kg: %.2f\n",Donantes[ID-1].Peso);
- printf("Grupo sanguineo: %s\n",Donantes[ID-1].GrupoSanguineo);
- printf("Donado: %dML\n",Donantes[ID-1].ML);
- printf("\n\n");
- }
- }
- }
- */
- int main(){
- int Menu=0;
- printf("\t\t\t\t>>>Banco de sangre<<<\n\n");
- do{
- printf("Registrar donantes(1)\n");
- printf("Lista de donantes(2)\n");
- printf("Busqueda de donantes(3)\n");
- printf("Salir(4)\n");
- scanf("%d",&Menu);
- switch(Menu){
- case 1: {
- Donar();
- break;
- }
- case 2:
- {
- if (Insertar==NULL)
- {
- fclose(Insertar);
- printf ("\nAun no se ha registrado un usuarios\n\n");
- }
- else
- {
- fclose(Insertar);
- Lista();
- }
- break;
- }
- case 3:
- {
- void Busqueda();
- Busqueda();
- break;
- }
- }
- }while(Menu !=4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment