Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/08/2014, 11:40
Avatar de Drewermerc
Drewermerc
 
Fecha de Ingreso: febrero-2014
Mensajes: 185
Antigüedad: 10 años, 3 meses
Puntos: 5
Respuesta: Guardar hora y fecha en un archivo

Hola amigo.
Bueno pues creo que lo que quieres hacer es algo como esto.

Código C:
Ver original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define NOM_FILE "date.txt"
  5. int main()
  6. {
  7. FILE    *file;
  8. time_t  tiempo;
  9. struct  tm  *timelocal;
  10. char    out_time[128],  d[25];
  11.  
  12. tiempo = time(0);
  13. timelocal = localtime(&tiempo);
  14. strftime(out_time, sizeof(out_time), "%d/%m/%y  %H:%M:%S", timelocal);
  15.  
  16. if ( ((file = fopen(NOM_FILE, "a")) == NULL) || ((file = fopen(NOM_FILE, "r")) == NULL))
  17.     file = fopen(NOM_FILE, "w");
  18.  
  19. if ( (file = fopen(NOM_FILE, "a")) == NULL)
  20. {
  21.     perror(NOM_FILE);
  22.     return EXIT_FAILURE;
  23. }
  24.  
  25. fprintf(file, "%s\n", out_time);
  26. fclose(file);
  27.  
  28. if ( (file = fopen(NOM_FILE, "r")) == NULL)
  29. {
  30.     perror(NOM_FILE);
  31.     return EXIT_FAILURE;
  32. }
  33. printf("las fechas del archivo son:\n");
  34. while (fgets(d, (int) sizeof d, file) != NULL)
  35.     printf("%s",d);
  36.  
  37. fclose(file);
  38. return(0);
  39. }

y bueno para la explicación de las funciones, estructura y tipo de datos para obtener la fechar aquí te dejo la información.
http://c.conclase.net/librerias/?ansifun=strftime

Bueno espero que te sirva.
Saludos.
Drewermerc.