Created
August 13, 2017 23:26
-
-
Save OverlordEx3/f13ea13d74e542a03eadecbb26040e34 to your computer and use it in GitHub Desktop.
Menu ABM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* File: menu.c | |
* Author: Hernandez Gabriel | |
* | |
* Created on 5 de julio de 2016, 00:59 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
typedef struct{ | |
unsigned int cp; | |
char nombre[30]; | |
int habitantes;/*--habitantes.*/ | |
float superficie; | |
unsigned int estado; | |
}FormularioDatos; | |
void Alta(){ /*Comienzo del proc.*/ | |
FormularioDatos Localidad; | |
int i; | |
char opc1; | |
FILE *fp; | |
printf("Usted eligio alta, esta seguro (S/N): "); | |
scanf("%c",&opc1); | |
fflush(stdin); | |
if((opc1 != 's') && (opc1 != 'S')) { | |
printf("no estas seguro :( \n"); | |
return; | |
} | |
fp = fopen("Alta.txt","ab+"); //creo el archivo.txt | |
if(!fp) { | |
return; | |
} | |
for(i=0;i<=19;i++){ /*Verifica en que lugar se puede ingresar los datos.*/ | |
if(Localidad.estado == 0) { | |
break; /*salto de linea*/ | |
} | |
} | |
system("cls"); | |
printf("Ingrese codigo postal: "); | |
scanf("%u",&Localidad.cp); | |
fflush(stdin); | |
printf("Ingrese un Nombre: "); | |
fgets(Localidad.nombre, 29, stdin); | |
fflush(stdin); | |
printf("Ingrese cantidad de habitantes: "); | |
scanf("%d",&Localidad.habitantes); | |
fflush(stdin); | |
printf("Ingrese la superficie: "); | |
scanf("%f",&Localidad.superficie); | |
fflush(stdin); | |
Localidad.estado=1; | |
fwrite(&Localidad, sizeof(Localidad), 1, fp); | |
fclose(fp); | |
/*system("clr"); borrar patalla*/ | |
printf("Los datos se han guardado\n"); | |
getchar(); | |
fflush(stdin); | |
} | |
//No se hacen operaciones sobre el archivo? | |
void Baja(){/*Comienzo del proc.*/ | |
FormularioDatos Localidad; | |
char opc2 = 0; | |
int pos = 0; | |
// FILE *ArchivoOriginal; | |
// FILE *ArchivoExterno; | |
printf("\nUsted eligio baja, esta seguro (S/N): "); | |
scanf("%c",&opc2); | |
if(opc2 == 's' || opc2 == 'S'){ | |
printf("Eliga la pocicion que quiera borrar: "); | |
scanf("%d",&pos); | |
Localidad.cp = 0; | |
strcpy(Localidad.nombre,""); /*borrar cadena*/ | |
Localidad.habitantes = 0; | |
Localidad.superficie = 0; | |
Localidad.estado = 0; | |
/* system("clr"); /*borrar patalla*/ | |
printf("Se borro la informacion..\n"); | |
getchar(); | |
return; | |
} | |
else{ | |
/* system("clr");*/ | |
printf("No esta seguro :( \n"); | |
getchar(); | |
} | |
} | |
void Modificar(){ | |
FormularioDatos Localidad; | |
int pocicion = 0; | |
int modif = 0; | |
int i = 0; | |
char opc3 = 0; | |
fflush(stdin); | |
printf("\nUsted eligio modificar, esta seguro (S/N): "); | |
scanf("%c",&opc3); | |
if(opc3 == 's' || opc3 == 'S'){ | |
printf("Eliga la pocicion que quiera modificar (empieza desde 0): "); | |
scanf("%d",&pocicion); | |
for(i=0;i<=19;i++){ | |
if(pocicion == i){ | |
while(modif!=5){ | |
fflush(stdin); | |
printf("* Modificar\n"); | |
printf("* 1.cp\n"); | |
printf("* 2.nombre\n"); | |
printf("* 3.cantidad\n"); | |
printf("* 4.superficie\n"); | |
printf("* 5.salir\n"); | |
printf("Eliga la opcion: "); | |
modif = getchar(); | |
switch(modif){ | |
case '1': | |
printf("\ningrese nuevo cp: "); | |
scanf("%d",&Localidad.cp); | |
printf("\nSe a ingresado nuevo cp."); | |
break; | |
case '2': | |
printf("\ningrese nuevo nombre: "); | |
scanf("%d",&Localidad.nombre); | |
printf("\nSe a ingresado nuevo nombre."); | |
break; | |
case '3': | |
printf("\ningrese nuevo habitantes: "); | |
scanf("%d",&Localidad.habitantes); | |
printf("\nSe a ingresado nuevo habitantes."); | |
break; | |
case '4': | |
printf("\ningrese nuevo superficie: "); | |
scanf("%d",&Localidad.superficie); | |
printf("\nSe a ingresado nuevo superficie."); | |
break; | |
case '5': | |
modif = 5; | |
break; | |
case '\n': | |
printf("\nUsted no selecciono nada..."); | |
break; | |
default: | |
printf("\nUsted apreto una tecla incorrecta...\a"); | |
} | |
} | |
} | |
} | |
} | |
else{ | |
printf("\nNo esta seguro..."); | |
return; | |
} | |
} | |
void Listado(){ /*Comienzo del proc.*/ | |
FILE *ArchivoListado; | |
FormularioDatos Localidad; | |
ArchivoListado = fopen ( "Alta.txt", "rb+" ); | |
char Opc4; | |
printf("\nUsted eligio listado, esta seguro (S/N): "); | |
Opc4 = getchar(); | |
fflush(stdin); | |
if((Opc4 != 's') && (Opc4 != 'S')){ | |
printf("no estas seguro :( \n"); | |
return; | |
} | |
if (!ArchivoListado) { | |
exit(1); | |
return; | |
} | |
printf("\n"); | |
while(fread(&Localidad, sizeof(Localidad), 1, ArchivoListado) > 0){ | |
printf("CP: %d\nNombre: %sCantidad de habitantes: %d\nSuperficie: %.1f\n\n\n", Localidad.cp, Localidad.nombre, Localidad.habitantes, Localidad.superficie); | |
} | |
fclose(ArchivoListado); | |
/* system("clr"); /*borrar patalla*/ | |
printf("Apriete una tecla para continuar..."); | |
getchar(); | |
return; | |
} | |
int main(int argc, char** argv) { | |
int opcion = 0; | |
while(opcion != '5') { | |
printf("****** MENU ******\n"); | |
printf("* 1.ALTA *\n"); | |
printf("* 2.BAJA *\n"); | |
printf("* 3.MODIFICACION *\n"); | |
printf("* 4.LISTADO *\n"); | |
printf("* 5.SALIR *\n"); | |
printf("Eliga un numero: "); | |
opcion = getchar(); | |
fflush(stdin); | |
system("cls"); | |
switch (opcion){ | |
case '1': | |
Alta(); | |
break; | |
case '2': | |
Baja(); | |
break; | |
case '3': | |
Modificar(); | |
break; | |
case '4': | |
Listado(); | |
break; | |
case '5': | |
break; //Se debería evaluar en el while() | |
case '\n': | |
printf("\nUsted no selecciono nada..."); | |
break; | |
default: | |
printf("\nUsted apreto una tecla incorrecta...\a"); | |
break; | |
} | |
system("CLS"); | |
} | |
printf("Usted salio del menu.... \n"); | |
printf("Press enter to continue ..."); | |
getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment