Como hago que los daros se guarden en un archivo de texto y retomarlos
Publicado por jorge (7 intervenciones) el 24/09/2020 23:55:21
Aqui esta el codigo necesito que se guarde en un archivo de texto los datos alguien podira ayudarme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct agenda {
char nom[15];
int t_f;
int t_m;
char dir[30], email[40], grupos[12];
} control[100];
int cont=0;
void agregar();
void buscar();
void contactos();
main(){
int opc;
do{
system("cls");
printf("MENU\n");
printf("1.Agregar\n");
printf("2.Buscar\n");
printf("3.Ver todos los contactos\n");
printf("4.Salir\n");
scanf("%d", &opc);
switch(opc){
case 1:
agregar();
system("pause");
break;
case 2:
buscar();
system("pause");
break;
case 3:
contactos();
system("pause");
break;
}
}while(opc!=4);
return 0;
}
void agregar(){
system("cls");
fflush(stdin);
printf("\n%d.Nombre de contacto:", (cont+1));
gets(control[cont].nom);
fflush(stdin);
printf("\nTel\202fono fijo:");
scanf("%d", &control[cont].t_f);
fflush(stdin);
printf("\nTel\202fono m\242vil:");
scanf("%d", &control[cont].t_m);
fflush(stdin);
printf("\nDirecci\242n:");
gets(control[cont].dir);
fflush(stdin);
printf("\nE-mail:");
gets(control[cont].email);
fflush(stdin);
printf("\nEmpresa:");
gets(control[cont].grupos);
cont++;
}
void buscar(){
char busca[15];
int i;
system("cls");
fflush(stdin);
printf("\nBuscar contacto\nIngrese el nombre del contacto:");
gets(busca);
for(i=0;i<cont;i++){
if(strcmpi(busca,control[i].nom)==0){
printf("\nNombre: %s\n", control[i].nom);
printf("Tel\202fono fijo: %d\n", control[i].t_f);
printf("Tel\202fono m\242vil: %d\n", control[i].t_m);
printf("Direcci\242n: %s\n", control[i].dir);
printf("E-mail: %s\n", control[i].email);
printf("Empresa: %s\n", control[i].grupos);
}
}
}
void contactos(){
int aux, i, j;
char auxc[50];
system("cls");
for(i=0;i<cont-1;i++){
for(j=0;j<cont-1-i;j++){
if(strcmp(control[j].nom,control[j+1].nom)>0){
strcpy(auxc,control[j].nom);
strcpy(control[j].nom,control[j+1].nom);
strcpy(control[j+1].nom,auxc);
aux = control[j].t_f;
control[j].t_f = control[j+1].t_f;
control[j+1].t_f = aux;
aux = control[j].t_m;
control[j].t_m = control[j+1].t_m;
control[j+1].t_m = aux;
strcpy(auxc,control[j].dir);
strcpy(control[j].dir,control[j+1].dir);
strcpy(control[j+1].dir,auxc);
strcpy(auxc,control[j].email);
strcpy(control[j].email,control[j+1].email);
strcpy(control[j+1].email,auxc);
strcpy(auxc,control[j].grupos);
strcpy(control[j].grupos,control[j+1].grupos);
strcpy(control[j+1].grupos,auxc);
}
}
}
printf("\nAgenda.\n");
for(i=0;i<cont;i++){
printf("\n%d.Nombre: %s\n",(i+1), control[i].nom);
printf("Tel\202fono fijo: %d\n", control[i].t_f);
printf("Tel\202fono m\242vil: %d\n", control[i].t_m);
printf("Direcci\242n: %s\n", control[i].dir);
printf("E-mail: %s\n", control[i].email);
printf("Empresa: %s\n", control[i].grupos);
}
}
Valora esta pregunta
0