C/Visual C - necesito que alguién me ayude con una duda

 
Vista:

necesito que alguién me ayude con una duda

Publicado por Lucas (1 intervención) el 06/02/2007 20:50:30
Hola gente, como va todo?, bueno espero que alguién pueda ayudarme porque estaba programando una agenda en C utilizando archivos, y no me sale la parte para de modificar... el algoritmo que yo hice es el siguiente...

void modificar()
{
char name[38];
char nombre[38];
char apellido[38];
char domicilio[38];
char telefono[38];
char celular[38];
char mail[38];
char info[38];
struct agendita agenda;
FILE* contacto;
clrscr();
textbackground(BLUE);
textcolor(WHITE);
gotoxy(21,9); cprintf("MODIFICACIONES DE CONTACTOS");
textbackground(BLACK);
textcolor(WHITE);
gotoxy(23,12); printf("INGRESAR EL NOMBRE DEL CONTACTO:");
_setcursortype(_NORMALCURSOR);
gotoxy(24,15); gets(name);
_setcursortype(_NOCURSOR);
contacto=fopen("c:\\CONTACTOS.dat","r+b");
rewind(contacto);
fread(&agenda,sizeof(agendita),1,contacto);
while(!feof(contacto))
{
if(strcmpi(agenda.nombre,name) ==0)
{
ficha(); // ESTA ES UNA FUNCION QUE DEFINO Y DECLARO ANTES
_setcursortype(_NORMALCURSOR);
//NOMBRE
gotoxy(22,10); gets(nombre);
strcpy(agenda.nombre,nombre);

//APELLIDO
gotoxy(22,12); gets(apellido);
strcpy(agenda.apellido,apellido);

//DOMICILIO
gotoxy(22,14); gets(domicilio);
strcpy(agenda.domicilio,domicilio);

//TELEFONO
gotoxy(22,16); gets(telefono);
strcpy(agenda.telefono,telefono);

//CELULAR
gotoxy(22,18); gets(celular);
strcpy(agenda.celular,celular);

//MAIL
gotoxy(22,20); gets(mail);
strcpy(agenda.mail,mail);

//INFO
gotoxy(22,22); gets(info);
strcpy(agenda.info,info);

//ESCRIBO LAS MODIFICACIONES EN EL ARCHIVO
fwrite(&agenda,sizeof(agendita),1,contacto);
break;
}
else
{
PRINTF("no se pudo modificar");
}
fread(&agenda,sizeof(agendita),1,contacto);
}
fclose(contacto);
getch();
}

lo que sucede es que yo agrego una persona, y la escribo en un archivo, y después para modificar leo el archivo y escribo lo que modifiqué si lo encontró, pero no me modifica nada :S, y no logro encontrar el error, espero que puedan ayudarme gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:necesito que alguién me ayude con una duda

Publicado por Nelek (816 intervenciones) el 13/02/2007 07:57:43
The character string mode specifies the type of access requested for the file, as follows:

"r"

Opens for reading. If the file does not exist or cannot be found, the fopen call fails.

"w"

Opens an empty file for writing. If the given file exists, its contents are destroyed.

"a"

Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn‚t exist.

"r+"

Opens for both reading and writing. (The file must exist.)

"w+"

Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.

"a+"

Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn‚t exist.


Segun la ayuda de VisualC++ no hay ninguna opcion que te valide la linea que tienes en tu codigo:

contacto=fopen("c:\\CONTACTOS.dat","r+b");

no será:

contacto=fopen("c:\\CONTACTOS.dat",r+w); ????
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:necesito que alguién me ayude con una duda

Publicado por Nelek (816 intervenciones) el 13/02/2007 07:59:28
Perdon, mirando mas detenidamente... la opcion es r+ (abrir para leer y escribir, pero teniendo que existir el archivo previamente)

contacto=fopen("c:\\CONTACTOS.dat",r+);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Olvidate de lo que dije arriba

Publicado por Nelek (816 intervenciones) el 13/02/2007 08:03:01
Perdona, me comi parte de la pagina de ayuda. Tu comando esta bien. Por lo demas a mi tu programa me parece correcto.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar