Ver Mensaje Individual
  #4 (permalink)  
Antiguo 03/04/2011, 16:25
Trovaz
 
Fecha de Ingreso: octubre-2010
Ubicación: Edo. de México
Mensajes: 94
Antigüedad: 13 años, 6 meses
Puntos: 9
Respuesta: escribir fecha en un fichero

Aqui te pongo un ejemplo muy sencillo de como obtener la hora con formato, Ya solo queda hacer un fprintf para mandarla a un archivo. Salu2

Código c:
Ver original
  1. #include <time.h>
  2. #include <locale.h>
  3. #include <langinfo.h>
  4. #include <string.h>
  5.  
  6. int obtenHora(char *formato, char **destino){
  7.   *destino = NULL;
  8.   time_t rawtime;
  9.   struct tm *timeinfo;
  10.   char buffer[80];
  11.  
  12.   time(&rawtime);
  13.   timeinfo = localtime(&rawtime);
  14.   strftime(buffer, sizeof(buffer), formato, timeinfo);
  15.   *destino = (char *)malloc((strlen(buffer) + 1) * sizeof(char));
  16.   strcpy(*destino, buffer);
  17.   return 0;
  18. }
  19.  
  20. int main(void){
  21.   char *hora = NULL;
  22.   obtenHora("%Y%m%d_%H%M%S", &hora);
  23.   printf("%s\n", hora);
  24.   if(hora != NULL){
  25.     free(hora);
  26.     hora = NULL;
  27.   }
  28.   return 0;
  29. }