Ir para conteúdo

Mohsen

Membros
  • Postagens

    2
  • Registro em

  • Última visita

Conquistas de Mohsen

0

Reputação

  1. Hey every body! i am trying to do a function with time output (i am beginner) but my code dont work in non form function it is working but when i am trying to convert that as function dont work have any idea? both code are here non function form ------------------------- It work---------------------- #include <stdio.h> /* puts */ #include <time.h> /* time_t, struct tm, time, localtime, strftime */ #include <iostream> using namespace std; int main () { time_t rawtime; struct tm * timeinfo; char buffer [80]; int mili; int dt; dt = 5; mili = dt; rawtime = 1660237353.0; timeinfo = localtime(&rawtime); strftime (buffer,80,"%Y-%m-%d %H:%M:%S",timeinfo); //puts (buffer); char currentTime[84] = ""; sprintf(currentTime, "%s.%03d", buffer,mili); printf("current time: %s \n", currentTime); return 0; } -------------------------------------- functional form which not work _______________ #include <stdio.h> /* puts */ #include <time.h> /* time_t, struct tm, time, localtime, strftime */ #include <string> #include <iostream> #include <cstring> using namespace std; string get_time(double _timstampp, int fraction) { time_t rawtime; struct tm *timeinfo; char buffer [80]; char currentTime[84]; rawtime = _timstampp; timeinfo = localtime(&rawtime); strftime (buffer,80,"%Y-%m-%d %H:%M:%S",timeinfo); sprintf(currentTime, "%s.%03d", buffer,fraction); return currentTime; } int main () { double _timstamp; int dt; dt = 5; _timstamp = 1660237353.0; char* time[84]; //time = get_time(_timstamp,dt); printf("current time: %s \n",get_time(_timstamp,dt)); return 0; }
×
×
  • Criar Novo...