<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<STYLE type=text/css>DIV {
MARGIN: 0px
}
</STYLE>
<META content="MSHTML 6.00.2900.3020" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hola Alejandro,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>puedes usar ficheros donde guardes la información
que desees y luego cuando vuelvas a abrir tu programa de nuevo puedes recuperar
esos datos, borrar algunos, añadir más, etc. Consulta el siguiente
link:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><A
href="http://c.conclase.net/curso/index.php?cap=039">http://c.conclase.net/curso/index.php?cap=039</A></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Un saludo,</FONT></DIV>
<DIV><FONT face=Arial size=2>Juan Antonio.</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=alepelexo@yahoo.es href="mailto:alepelexo@yahoo.es">Alejandro Vilar
López</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A
title=cconclase@listas.conclase.net
href="mailto:cconclase@listas.conclase.net">cconclase@listas.conclase.net</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Saturday, January 13, 2007 6:19
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [C con Clase] Guardar
datos</DIV>
<DIV><BR></DIV>
<DIV
style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV>Hola, me llamo Alejandro y soy español.</DIV>
<DIV>Tengo 13 años y me gusta la informática. Antes había hecho páginas web
con HTML pero ahora me he metido a la programación</DIV>
<DIV>Me gustaría saber si se pueden guardar los datos que introduzcas en un
programa y que al cerrar el programa no los pierdas. Os pregunto esto para el
problema 1 de la parte de estructuras en el que hay que crear una agenda
telefónica y para el que yo he usado este código:</DIV>
<DIV> </DIV>
<DIV><FONT color=#008000 size=2>
<P>//Escribir un programa que almacene en un array los nombres y números de
teléfono de 10 personas.</P>
<P>//El programa debe leer los datos introducidos por el usuario y guardarlos
en memoria. </P>
<P>//Después debe ser capaz de buscar el nombre correspondiente a un número de
teléfono y el teléfono </P>
<P>//correspondiente a una persona. Ambas opciones deben se accesibles a
través de un menú, así como la </P>
<P>//opción de salir del programa. El menú debe tener esta forma, más o menos:
</P>
<P>//a) Buscar por nombre</P>
<P>//b) Buscar por número de teléfono</P>
<P>//c) Salir</P>
<P>//Pulsa una opción:</P>
<P>//4/1/2007 Alejandro Vilar López</P></FONT><FONT color=#0000ff size=2>
<P>#include</FONT><FONT color=#800000 size=2><iostream></FONT><FONT
color=#008000 size=2>//Librería para usar cout</P></FONT><FONT color=#0000ff
size=2>
<P>using</FONT><FONT size=2> </FONT><FONT color=#0000ff
size=2>namespace</FONT><FONT size=2> std;</P></FONT><FONT color=#0000ff
size=2>
<P>struct</FONT><FONT size=2> Datos</FONT><FONT color=#008000
size=2>//Estructura donde guardaré los datos</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2>
nombre[15];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde
guardaré el nombre</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2>
telefono;</FONT><FONT color=#008000 size=2>//Variable entera para guardar el
teléfono</P></FONT><FONT size=2>
<P>}Persona[100];</FONT><FONT color=#008000 size=2>//Array donde se guerdan
las personas</P></FONT><FONT color=#0000ff size=2>
<P>int</FONT><FONT size=2> main()</FONT><FONT color=#008000 size=2>//Función
principal</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2>
opcion[2];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde
guardaré la respuesta</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2>
respuesta1[2];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde
guardaré otra respuesta</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2>
respuesta2[2];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde
guardaré otra respuesta</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2>
respuesta3[2];</FONT><FONT color=#008000 size=2>//Variable de caracteres donde
guardaré otra respuesta</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2>
cnombre[15];</FONT><FONT color=#008000 size=2>//Variable para comprobar el
nombre</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2>
ctelefono;</FONT><FONT color=#008000 size=2>//Variable par comprobar el
teléfono</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> k;</FONT><FONT
color=#008000 size=2>//Variable entera que usaré de contador en los
bucles</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> n;</FONT><FONT
color=#008000 size=2>//Variable que usaré como contador en los
bucles</P></FONT><FONT size=2>
<P></P>
<P>Start:</FONT><FONT color=#008000 size=2>//Etiqueta para
goto</P></FONT><FONT size=2>
<P>cout << endl << </FONT><FONT color=#800000 size=2>"Que deseas
hacer? (a/b/c/d)"</FONT><FONT size=2> << endl << </FONT><FONT
color=#800000 size=2>"a) Introducir datos"</FONT><FONT size=2> <<
endl</P>
<P><<</FONT><FONT color=#800000 size=2>"b) Buscar por
nombre"</FONT><FONT size=2> << endl << </FONT><FONT color=#800000
size=2>"c) Buscar por telefono"</FONT><FONT size=2> << endl <<
</FONT><FONT color=#800000 size=2>"d) Salir"</FONT><FONT size=2> <<
endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> opcion;</FONT><FONT color=#008000 size=2>//Te deja
responder</P></FONT><FONT size=2>
<P></P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(opcion[0] ==
</FONT><FONT color=#800000 size=2>'a'</FONT><FONT size=2> || opcion[0] ==
</FONT><FONT color=#800000 size=2>'A'</FONT><FONT size=2>)</FONT><FONT
color=#008000 size=2>//Si respondes a</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(k = 0; k <=
99; k ++)</FONT><FONT color=#008000 size=2>//Bucle for para meter el
nombra</P></FONT><FONT size=2>
<P>{</P>
<P>cout << endl << </FONT><FONT color=#800000 size=2>"Introduce el
nombre (maximo 15 letras y sin"</FONT><FONT size=2> </P>
<P></FONT><FONT color=#800000 size=2>" espacios): "</FONT><FONT size=2>
<< endl;</FONT><FONT color=#008000 size=2>//Muestra esto</P></FONT><FONT
size=2>
<P>cin >> Persona[k].nombre;</FONT><FONT color=#008000 size=2>//Te deja
meter el nombre</P></FONT><FONT size=2>
<P>cout << </FONT><FONT color=#800000 size=2>"Introduce el telefono:
"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000
size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> Persona[k].telefono;</FONT><FONT color=#008000 size=2>//Te
deja meter el teléfono</P></FONT><FONT size=2>
<P>cout << </FONT><FONT color=#800000 size=2>"Introducir mas personas?
(s/n)"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000
size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> respuesta1;</FONT><FONT color=#008000 size=2>//Te deja
contestar</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(respuesta1[0] ==
</FONT><FONT color=#800000 size=2>'n'</FONT><FONT size=2> || respuesta1[0] ==
</FONT><FONT color=#800000 size=2>'N'</FONT><FONT size=2>)</FONT><FONT
color=#0000ff size=2>goto</FONT><FONT size=2> Start;</FONT><FONT color=#008000
size=2>//Si se cumple, hace esto</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P></P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(opcion[0] ==
</FONT><FONT color=#800000 size=2>'b'</FONT><FONT size=2> || opcion[0] ==
</FONT><FONT color=#800000 size=2>'B'</FONT><FONT size=2>)</FONT><FONT
color=#008000 size=2>//Si respondes b hace lo siguiente</P></FONT><FONT
size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(n = 0; n <=
99; n ++)</P>
<P>{</P>
<P>cout << endl << </FONT><FONT color=#800000 size=2>"Introduce el
nombre a buscar:"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000
size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> cnombre;</FONT><FONT color=#008000 size=2>//Te deja meter el
nombre</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(k = 0; k <=99;
k ++)</FONT><FONT color=#008000 size=2>//Bucle para buscar el
telefono</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(cnombre[0] ==
Persona[k].nombre[0] </P>
<P>&& cnombre[1] == Persona[k].nombre[1])</FONT><FONT color=#008000
size=2>//Si se cumple, hace esto</P></FONT><FONT size=2>
<P>{</P>
<P>cout << </FONT><FONT color=#800000 size=2>"Telefono de "</FONT><FONT
size=2> << Persona[k].nombre << </FONT><FONT color=#800000
size=2>": "</FONT><FONT size=2> </P>
<P><< Persona[k].telefono << endl;</FONT><FONT color=#008000
size=2>//Muestra esto</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P>cout << </FONT><FONT color=#800000 size=2>"Buscar otro telefono?
(s/n)"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000
size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> respuesta2;</FONT><FONT color=#008000 size=2>//Te deja
contestar</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(respuesta2[0] ==
</FONT><FONT color=#800000 size=2>'n'</FONT><FONT size=2> || respuesta2[0] ==
</FONT><FONT color=#800000 size=2>'N'</FONT><FONT size=2>)</FONT><FONT
color=#0000ff size=2>goto</FONT><FONT size=2> Start;</FONT><FONT color=#008000
size=2>//Si se cumple, vuelves a empezar</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P></P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(opcion[0] ==
</FONT><FONT color=#800000 size=2>'c'</FONT><FONT size=2> || opcion[0] ==
</FONT><FONT color=#800000 size=2>'C'</FONT><FONT size=2>)</FONT><FONT
color=#008000 size=2>//Si respondes c</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(n = 0; n <=
99; n ++)</P>
<P>{</P>
<P>cout << endl << </FONT><FONT color=#800000 size=2>"Introduce el
telefono:"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000
size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> ctelefono;</FONT><FONT color=#008000 size=2>//Te deja meter el
nombre</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>(k = 0; k <=99;
k ++)</FONT><FONT color=#008000 size=2>//Bucle para buscar el
telefono</P></FONT><FONT size=2>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(ctelefono ==
Persona[k].telefono)</FONT><FONT color=#008000 size=2>//Si se cumple, hace
esto</P></FONT><FONT size=2>
<P>{</P>
<P>cout << </FONT><FONT color=#800000 size=2>"El telefono es
de"</FONT><FONT size=2> << </FONT><FONT color=#800000 size=2>":
"</FONT><FONT size=2> </P>
<P><< Persona[k].nombre << endl;</FONT><FONT color=#008000
size=2>//Muestra esto</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>break</FONT><FONT size=2>;</FONT><FONT
color=#008000 size=2>//Corta el bucle</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P>cout << </FONT><FONT color=#800000 size=2>"Buscar otro?
(s/n)"</FONT><FONT size=2> << endl;</FONT><FONT color=#008000
size=2>//Muestra esto</P></FONT><FONT size=2>
<P>cin >> respuesta3;</FONT><FONT color=#008000 size=2>//Te deja
contestar</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2>(respuesta3[0] ==
</FONT><FONT color=#800000 size=2>'n'</FONT><FONT size=2> || respuesta3[0] ==
</FONT><FONT color=#800000 size=2>'N'</FONT><FONT size=2>)</FONT><FONT
color=#0000ff size=2>goto</FONT><FONT size=2> Start;</FONT><FONT color=#008000
size=2>//Si se cumple, vuelves a empezar</P></FONT><FONT size=2>
<P>}</P>
<P>}</P>
<P></P>
<P>cin.get();</FONT><FONT color=#008000 size=2>//Mantiene abierto el
programa</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> 0;</P>
<P>}</P></FONT></DIV>
<DIV> </DIV>
<DIV>Gracias por adelantado y un saludo.</DIV></DIV><BR>
<HR SIZE=1>
<BR><FONT face=Verdana size=-2>LLama Gratis a cualquier PC del
Mundo.<BR>Llamadas a fijos y móviles desde 1 céntimo por minuto.<BR><A
href="http://us.rd.yahoo.com/mail/es/tagline/messenger/*http://es.voiceyahoo.com/">http://es.voice.yahoo.com</A></FONT>
<P>
<HR>
<P></P>_______________________________________________<BR>Cconclase mailing
list<BR>Cconclase@listas.conclase.net<BR>http://listas.conclase.net/mailman/listinfo/cconclase_listas.conclase.net<BR></BLOCKQUOTE></BODY></HTML>