I found a code and I want to use it. When I run it from a terminal by ./code 20181010 0810, it works perfectly. I was trying to rewrite this code into function. The main code was declared by
int main (int argc, char *inp[]) { //some calculations } So, I changed it into:
int calc(int argc, char *inp[]) { //some calculations }
and the write main code with additional calculations:
int calc(int argc, char *inp[]); int main(int argc, char *inp[]) { char* c_date; char* c_hour; time_t timer; char buffer1[26], buffer2[26]; struct tm* tm_info; time(&timer); tm_info = localtime(&timer); strftime(buffer1, 26, "%Y%m%d", tm_info); c_date = buffer1; strftime(buffer2, 26, "%H%M", tm_info); puts(buffer2); c_hour = buffer2; calc(&c_date, &c_hour); return 0; } And for example, for the time now 20180212 1045 it gives me 201802112355, when it should give me 201802121050.
What can be wrong?
char**while anintis expected, isn't the best idea.calcmaking integer from pointer without a cast,intexpected but argument of typechar**.... how about fixing those before you bother with the expected / observed result? (Voting to close as "too broad", could also be absence of a minimal reproducible example.)