Ver Mensaje Individual
  #8 (permalink)  
Antiguo 18/03/2005, 01:56
Avatar de Eternal Idol
Eternal Idol
 
Fecha de Ingreso: mayo-2004
Ubicación: Lucentum
Mensajes: 6.192
Antigüedad: 20 años, 10 meses
Puntos: 74
Acá tenes un ejemplo con una estructura de tamaño fijo:

Código:
#include <windows.h>
#include <stdio.h>

struct registro
{
  char usuario[256];
  char control;
};

void main()
{
  registro first;
  strcpy(first.usuario, "Juan");
  first.control = 'N';
  registro second;
  strcpy(second.usuario, "Jose");
  second.control = 'Y';
  FILE *Out = fopen("c:\\struct_data.txt", "w+");
  fwrite(&first, sizeof(registro), 1, Out);
  fwrite(&second, sizeof(registro), 1, Out);
  fclose(Out);

  registro *primero = (registro*)malloc(sizeof(registro));
  registro *segundo = (registro*)malloc(sizeof(registro));
  FILE *In = fopen("c:\\struct_data.txt", "r+");
  fread(primero, sizeof(registro), 1, In);
  fread(segundo, sizeof(registro), 1, In);
  printf("Nombre %s\r\n", primero->usuario);
  printf("Control %c\r\n", primero->control);
  printf("Nombre %s\r\n", segundo->usuario);
  printf("Control %c\r\n", segundo->control);
  free(primero);
  free(segundo);
  fclose(In);
}
__________________
¡Peron cumple, Evita dignifica! VIVA PERON CARAJO