Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/07/2008, 11:25
clau2008
 
Fecha de Ingreso: julio-2008
Mensajes: 3
Antigüedad: 15 años, 10 meses
Puntos: 0
Archivos en C

No me funciona la simple apertura de un archivo binario en C, alguien me ayuda, paso el código: quiero cargar una estructurita en el archivo y luego verla;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct articulo
{
char Nombre[40];
int Nroarticulo;
int Cantidad;
char Rubro[20];
double Importe;
} arti;


FILE*f;
f == fopen("e:archivo1.dat","a");

if (!=f){
puts("ERROR AL ABRIR EL ARCHIVO");
exit(1);
}
//Carga de datos
{
printf("\n Ingrese los datos en el archivo");
printf("Ingrese N para terminar");
int c;
while(c=getch()!='N'){

puts ("Nombre del articulo");
gets (arti.Nombre);
puts ("Numero de articulo");
scanf ("%d",arti.Nroarticulo);
puts ("Cantidad");
scanf ("%d",arti.Cantidad);
puts ("Rubro");
scanf (arti.Rubro);
puts ("Importe");
scanf ("%d",arti.Importe);
printf("Desea cargar otro articulo:S/N");
getch();
return;
}

//Carga del Archivo
fwrite(arti,sizeof(f),1,f);

//Cerrar Archivo
fclose(f);
return 0;
}
//[email protected]
int WtF (FILE *f)
{
//abrirlo para leerlo
f=fopen("archivo1.dat","wb")
if (!f){
puts ("ERROR AL ABRIR EL ARCHIVO");
exit (1);
}
//Impresion del archivo
while not !EOF(f) do{
puts ("Nombre:");
printf ("%s\n",arti.Nombre);
puts ("Rubro");
printf ("%s\n",arti.Rubro);
puts ("Importe");
printf ("%d\n",arti.Importe);
puts ("Numero de articulo");
printf ("%d\n",arti.Nroarticulo);
puts ("Cantidad");
printf ("%d\n",arti.Cantidad);
}
//Cerrar Archivo
fclose(f);

return 0;
}

Gracias.