~eaglescreen/ple/2010-2011

« back to all changes in this revision

Viewing changes to BELMONTE RAFAEL 3ra EVALUACION/Ficheros Binarios/04_agenda.c

  • Committer: Rafael Belmonte
  • Date: 2011-04-07 02:45:16 UTC
  • Revision ID: eaglescreen@gmail.com-20110407024516-ed3zmrar45pfa9ot
Regular update

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#include "MiString.h"
14
14
//#include <conio.h>/*comentar en Unix*/
15
15
#include "uconio.h" /*comentar en Windows*/
16
 
 
 
16
 
17
17
#define NL '\n' //Cambiar: \n en Unix; \r en Windows
18
18
#define OK 0
19
19
#define ERR !OK
20
20
#define FICHERO "agenda.dat"
21
21
#define ESCAPE 27
22
 
#define NOM_CAD 30
 
22
#define NOM_CAD 30
23
23
#define TELF_CAD 11
24
24
 
25
25
#ifndef bool
38
38
/**************PROTOTIPOS****************/
39
39
bool AgregarContacto(FILE *);
40
40
int ImprimirMenu(void);
41
 
bool BuscarContacto(FILE *);
42
 
void Pausa(void);
43
 
unsigned Recorrer(FILE *);
 
41
bool BuscarContacto(FILE *);
 
42
void Pausa(void);
 
43
unsigned Recorrer(FILE *);
44
44
int Salir(void);
45
45
/****************************************/
46
46
 
57
57
                                                break;
58
58
                                                
59
59
                  case '2':             BuscarContacto(archivo);
60
 
                                                break;
61
 
                                                
62
 
                  case '3':             Recorrer(archivo);
63
 
                                                break;
64
 
                                                
65
 
                  case ESCAPE:  opt=Salir();
 
60
                                                break;
 
61
                                                
 
62
                  case '3':             Recorrer(archivo);
 
63
                                                break;
 
64
                                                
 
65
                  case ESCAPE:  opt=Salir();
66
66
                                                break;
67
67
      }
68
68
    }
120
120
bool BuscarContacto(FILE *archivo)
121
121
{
122
122
        char aux[NOM_CAD+3];
123
 
        char *resp;
 
123
        char *resp;
124
124
        bool found=FALSE;
125
125
        CONTACTO p1;
126
126
        aux[0]=NOM_CAD;
139
139
                        printf("\n\n\n    Encontrado:\n\n");
140
140
                        printf("\tNombre: %s\n",p1.nombre);
141
141
                        printf("\tEdad: %u\n",p1.edad);
142
 
                        printf("\tTelefono: %s\n",p1.telefono);
143
 
                        Pausa();
 
142
                        printf("\tTelefono: %s\n",p1.telefono);
 
143
                        Pausa();
144
144
                        found=TRUE;
145
145
                }
146
146
                fread(&p1,sizeof(CONTACTO),1,archivo);
147
147
                if (ferror(archivo)) return ERR;
148
148
        }
149
 
        fclose(archivo);
150
 
        if (!found)
151
 
        {
152
 
                clrscr();
153
 
                printf("\n\n\tNINGUNA COINCIDENCIA ENCONTRADA");
154
 
                Pausa();
 
149
        fclose(archivo);
 
150
        if (!found)
 
151
        {
 
152
                clrscr();
 
153
                printf("\n\n\tNINGUNA COINCIDENCIA ENCONTRADA");
 
154
                Pausa();
155
155
        }
156
156
        return OK;
157
 
}
158
 
 
159
 
unsigned Recorrer(FILE *fbin)
160
 
{
161
 
        unsigned int cont=0;
162
 
        CONTACTO p1;
163
 
        fbin=fopen(FICHERO,"rb");
164
 
        if (!fbin) return 0;
 
157
}
 
158
 
 
159
unsigned Recorrer(FILE *fbin)
 
160
{
 
161
        unsigned int cont=0;
 
162
        CONTACTO p1;
 
163
        fbin=fopen(FICHERO,"rb");
 
164
        if (!fbin) return 0;
165
165
        fread(&p1,sizeof(CONTACTO),1,fbin);
166
 
        if (ferror(fbin)) return ERR;
 
166
        if (ferror(fbin)) return 0;
167
167
        clrscr();
168
 
        while(!feof(fbin))
169
 
        {
 
168
        while(!feof(fbin))
 
169
        {
170
170
                printf("\n\n\n    CONTACTO %u\n\n",++cont);
171
171
                printf("\tNombre: %s\n",p1.nombre);
172
172
                printf("\tEdad: %u\n",p1.edad);
173
 
                printf("\tTelefono: %s\n",p1.telefono);
174
 
                Pausa();
175
 
        }
176
 
        printf("\tYa no hay mas contactos.");
177
 
        Pausa();
178
 
        return cont;
179
 
}
180
 
 
181
 
void Pausa(void)
182
 
{
183
 
        printf("\n\n  Pulse INTRO para continuar..");
184
 
        while(getch()!=NL);
185
 
}
186
 
 
187
 
int Salir()
188
 
{
189
 
        char aux[4];
190
 
        char *resp;
191
 
        aux[0]=1;
192
 
        do
193
 
        {
194
 
                clrscr();
195
 
                printf("\n\tEsta seguro de que quiere salir del programa?");
196
 
                printf("\n\t>");
197
 
                resp=cgets(aux);
198
 
        }
199
 
        while ((MiStricmp(resp,"y")) && (MiStricmp(resp,"n")));
200
 
        if (!MiStricmp(resp,"y"))       return ESCAPE;
201
 
        else    return 0;
202
 
}
 
173
                printf("\tTelefono: %s\n",p1.telefono);
 
174
                Pausa();
 
175
                fread(&p1,sizeof(CONTACTO),1,fbin);
 
176
                if (ferror(fbin)) return 0;
 
177
        }
 
178
        fclose(fbin);
 
179
        printf("\n\tYa no hay mas contactos.");
 
180
        Pausa();
 
181
        return cont;
 
182
}
 
183
 
 
184
void Pausa(void)
 
185
{
 
186
        printf("\n\n  Pulse INTRO para continuar..");
 
187
        while(getch()!=NL);
 
188
}
 
189
 
 
190
int Salir()
 
191
{
 
192
        char aux[4];
 
193
        char *resp;
 
194
        aux[0]=1;
 
195
        do
 
196
        {
 
197
                clrscr();
 
198
                printf("\n\tEsta seguro de que quiere salir del programa?");
 
199
                printf("\n\t>");
 
200
                resp=cgets(aux);
 
201
        }
 
202
        while ((MiStricmp(resp,"s")) && (MiStricmp(resp,"n")));
 
203
        if (!MiStricmp(resp,"s"))       return ESCAPE;
 
204
        else    return 0;
 
205
}