Вы находитесь на странице: 1из 6

#include #include #include #include

<conio.h> <stdio.h> <string.h> <stdlib.h>

struct proyectofinal { char char char char char char char char } datos; void main() { int opcion=0; char opc[6]; char dnibuscado[10],var; FILE *archivo; FILE *temporal; if(archivo=fopen("PROGRAMAFINAL.txt","w+")) do { clrscr(); freopen("PROGRAMAFINAL.txt","a+",archivo); printf("*************************** AGENDA DE ACTIVIDADES UMG ************** ********** \n\n"); printf(" 1---AGREGAR ACTIVIDADES \n"); printf(" 2---BUSQUEDA DE ACTIVIDADES \n"); printf(" 3---REGISTRO DE ACTIVIDADES \n"); printf(" 4---BORRAR ACTIVIDAD \n"); printf(" 5---SALIR Y CREDITOS \n\n\n"); printf("SELECCIONE UNA OPCION: "); gets(opc); opcion=atoi(opc); switch(opcion) { case 1: clrscr(); freopen("PROGRAMAFINAL.txt","a+",archivo); cprintf("\nUSTED ELIGIO LA OPCION 1: AGREGAR ACT actividad[40]; fecha[40]; nombre[15]; apellidos[15]; direccion[30]; numero[12]; email[40]; telefono[15];

IVIDAD...\n\n"); printf("\n\tNombre de Actividad: "); fflush(stdin); gets(datos.actividad); printf("\n\tFecha: "); fflush(stdin); gets(datos.fecha); printf("\n\tNombre: "); fflush(stdin); gets(datos.nombre); printf("\n\tApellido: "); fflush(stdin); gets(datos.apellidos); printf("\n\tDireccion: "); fflush(stdin); gets(datos.direccion); printf("\n\tNumero de Casa: ");fflush(stdin); gets(datos.numero); printf("\n\te-mail: ");fflush(stdin); gets(datos.email); printf("\n\tTelefono: ");fflush(stdin); gets(datos.telefono); fflush(stdin); if(fwrite(&datos,sizeof(datos),1,archivo)!=1) { printf("\n\tERROR........\n"); getch(); exit(2); } break; case 2: clrscr(); cprintf("\nUSTED ELIGIO LA OPCION 2: BUSCAR ACTI VIDAD\n\n"); rewind(archivo); printf("\n\tNOMBRE DE ACTIVIDAD A BUSCAR: "); fflush(stdin); gets(dnibuscado); var=fgetc(archivo); fseek(archivo,0L,SEEK_SET); while(var!=EOF) { if(fread(&datos,sizeof(datos),1,archivo)!=1) { printf("\n\tERROR NO SE ENCUENTRA LA ACTIVIDAD S OLICITADA"); fclose(archivo); getch(); break; } if(strcmp(dnibuscado,datos.actividad)==0) { opcion=6; printf("\n\tACTIVIDAD: "); fflush(stdin); puts(datos.actividad); printf("\n\tNombre: ");fflush(stdin); puts(datos.nombre); printf("\n\tApellido: ");fflush(stdin);

puts(datos.apellidos); printf("\n\tFecha: "); puts(datos.fecha); printf("\n\tDireccion: ");fflush(stdin); puts(datos.direccion); printf("\n\te-mail: ");fflush(stdin); puts(datos.email); printf("\n\tTelefono: ");fflush(stdin); puts(datos.telefono); getch(); } var=fgetc(archivo); fseek(archivo,-1L,SEEK_CUR); } if(opcion!=6) { printf("\nACTIVIDAD INGRESADA NO EXISTE"); getch(); } break; case 3: clrscr(); rewind(archivo); var=fgetc(archivo); fseek(archivo,0L,SEEK_SET); while(var!=EOF) { cprintf("\nUSTED ELIGIO LA OPCION 3: REGISTRO DE ACTIVIDADES\n\n"); if(fread(&datos,sizeof(datos),1,archivo)!=1) { printf("\n\tNO SE PUEDE COMPLETAR LA BUSQUEDA"); fclose(archivo); getch(); break; } opcion=6; printf("\n\tACTIVIDAD: "); fflush(stdin); puts(datos.actividad); printf("\n\tNombre: "); fflush(stdin); puts(datos.nombre); printf("\n\tApellido: "); fflush(stdin); puts(datos.apellidos); printf("\n\tFecha: "); fflush(stdin); puts(datos.fecha); printf("\n\tDireccion: "); fflush(stdin); puts(datos.direccion); printf("\n\tNumero de Casa: "); fflush(stdin); puts(datos.numero); printf("\n\te-mail: "); fflush(stdin );

puts(datos.email); printf("\n\tTelefono: "); fflush(stdin); puts(datos.telefono); getch(); var=fgetc(archivo); fseek(archivo,-1L,SEEK_CUR); } if(opcion!=6) { printf("\n NO SE ENCUENTRA LA ACTIVIDAD BUSCADA" ); getch(); } break; case 4: clrscr(); cprintf("\nUSTED ELIGIO LA OPCION 4: BORRAR ACTI VIDAD... \n\n"); if((temporal=fopen("TEMPORAL.txt","w+"))==NULL) { cprintf("\n\tERROR AL BORRAR LA ACTIVIDAD"); getch(); exit(1); } rewind(archivo); printf("\n\tINGRESE EL NOMBRE DE LA ACTIVIDAD A BORRAR: "); fflush(stdin); gets(dnibuscado); var=fgetc(archivo); fseek(archivo,0L,SEEK_SET); while(var!=EOF) { if(fread(&datos,sizeof(datos),1,archivo)!=1) { printf("\n\tERROR AL BORRAR LA ACTIVIDAD"); fclose(archivo); getch(); break; } if(strcmp(dnibuscado,datos.actividad)==0) { printf("\n\tActividad Eliminada\n"); opcion=6; printf("\n\tActividad: "); fflush(stdin); puts(datos.actividad); printf("\n\tNombre: "); fflush(stdin); puts(datos.nombre); printf("\n\tApellido: "); fflush(stdin); puts(datos.apellidos);

printf("\n\tFecha: "); fflush(stdin); puts(datos.fecha); printf("\n\tDireccion: "); fflush(stdin); puts(datos.direccion); printf("\n\tNumero: "); fflush(stdin); puts(datos.numero); printf("\n\te-mail: "); fflush(stdin); puts(datos.email); printf("\n\tTelefono: ");fflush(stdin); puts(datos.telefono); getch(); } else { if(fwrite(&datos,sizeof(datos),1,temporal)!=1) { printf("ntERROR AL BORRAR ACTIVIDAD"); getch(); exit(2); } fflush(stdin); } var=fgetc(archivo); fseek(archivo,-1L,SEEK_CUR); } rewind(temporal); freopen("PROGRAMAFINAL.txt","w",archivo); fflush(stdin); var=fgetc(temporal); fseek(temporal,0L,SEEK_SET); getch(); while(var!=EOF) { fflush(stdout); fflush(stderr); fflush(stdin); if(fread(&datos,sizeof(datos),1,temporal)!=1) { printf("\n\tERROR AL BORRAR ACTIVIDAD"); getch(); break; } fflush(stdin); if(fwrite(&datos,sizeof(datos),1,archivo)!=1) { printf("\n\tERROR AL BORRAR ACTIVIDAD"); getch(); break; } fflush(stdin); var=fgetc(temporal); fseek(temporal,-1L,SEEK_CUR); }

if(opcion!=6) { printf("\nACTIVIDAD INGRESADA NO EXISTE EN LA BA SE DE DATOS"); getch(); } if(!remove("TEMPORAL.txt")) printf("\nACTIVIDAD BORRADA"); else printf("\nERROR CRITICO AL TRATAR DE CERRAR DOC TEMPORAL"); break; case 5: clrscr(); gotoxy(20,3); printf("INTEGRANTES:\n\n"); gotoxy(20,5); printf(" MARVIN LOBOS\n"); gotoxy(20,6); printf(" MONICA ROMERO\n"); gotoxy(20,7); printf(" ENRIQUE URRUTIA\n"); gotoxy(20,8); printf(" KEVIN MARROQUIN\n"); gotoxy(20,9); printf(" EDGAR PANIAGUA\n"); gotoxy(20,13); printf("UNIVERSIDAD MARIANO GALVEZ DE GUATEMALA\n"); gotoxy(20,15); printf(" INGENIERIA EN SISTEMAS"); getch(); break; default: cprintf(" ######## ERROR OPCION NO VALIDA ##### ### "); getch(); break; } } while(opcion!=5); if(fclose(archivo)!=0) { cprintf("\n\tNO SE PUEDE CERRAR EL ARCHIVO"); getch(); exit(3); } }

Вам также может понравиться