c - fopen filename starts with weird dot -


https://i.stack.imgur.com/4tmgr.png

hi.

as may see i'm trying save recent data c project inside log file files name corresponds actual time/date.

while path combined , displayed correctly inside console file starts weird dot, more precise blank space followed dot , blank space, displayed in picture.

i'm using windows 7 64bit , cygwin64.

the relevant bits of code are:

#include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> void save_to_file(char* timestamp, char* homepath, int generation) char* create_timestamp(char* timestamp) int main(){     char homepath[28] = "d:\\cygwin64\\home\\ignite\\log\\";     int generation = 0;      char* timestamp = malloc (30 * sizeof(char));     create_timestamp(timestamp);     save_to_file(timestamp, homepath, generation); }  void save_to_file(char* timestamp, char* homepath, int generation){     char string[4];     char logchar[4] = "log";     char dot[] = {"."};     char fileend[5] = {".txt"};     char* path = malloc(60*sizeof(char));     strcpy(path, homepath);     strcat(path, logchar);     snprintf(string, 4, "%d", generation);     strcat(path, string);     strcat(path, dot);     strcat(path, timestamp);     strcat(path, fileend);     file* f = fopen(path, "ab+");     if(f == null){         printf("error opening file!\n");         exit(1);     }     else{         //write file     } } char* create_timestamp(char* timestamp){     time_t rawtime;     struct tm *info;     char buffer[30], *string, *work;     string = malloc (5* sizeof(char));     work = malloc (30* sizeof(char));     char point[] = {"."};     time( &rawtime );      info = localtime( &rawtime );     strcpy(buffer, asctime(info));      int n = info->tm_mday;     snprintf(string, 4, "%d", n);     strcpy(work, string);      n = (int) info->tm_mon + 1;     snprintf(string, 3, "%d", n);     strcat(work, point);     strcat(work, string);     ///*     n = info->tm_year + 1900;     snprintf(string, 5, "%d", n);     strcat(work, point);     strcat(work, string);       n = info->tm_hour;     snprintf(string, 3, "%d", n);     strcat(work, point);     strcat(work, string);      n = info->tm_min;     snprintf(string, 3, "%d", n);     strcat(work, point);     strcat(work, string);      n = info->tm_sec;     snprintf(string, 3, "%d", n);     strcat(work, point);     strcat(work, string);     strcpy(timestamp, work);     free(string);     return timestamp; } 

your array short. "d:\cygwin64\home\ignite\log\" 29 bytes. – melpomene


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -