To produce millisecond using clock function after strcat but it simply crash, what could be the problem?
FREObject result = 0;
uint32_t len = -1;
const uint8_t *str = 0;
char *temp = "Millisecond: ";
uint8_t *strAll;
clock_t curtime = clock();
double *asc = (double *) curtime; //Using double datatype?
if(FREGetObjectAsUTF8(argv[0], &len, &str) == FRE_OK) {
strAll = (char *)malloc(strlen(temp) + strlen(str) + 1 + strlen(asc) + 1);
strcpy(strAll,temp);
strcat(strAll,str);
strcat(strAll," ");
strcat(strAll,(char *)asc); //Is this correct?
}
FRENewObjectFromUTF8(strlen((const char *)strAll)+1, (const uint8_t *)strAll, &result);
return result;
The assignment to
ascis extremely dubious:You can measure the difference between two
clock()values, to determine the processor time used.You might get more nearly successful results with:
The
strlen()operation is undefined – under either definition ofasc:Then the
strcat()operation is going fail horribly; you have to convert thedoubleto a string before you can concatenate the string to another.So, you have a lot of work to do. You need to decide whether
clock()is the right system call. If it is, you have to fix the sizing and the conversion ofascorcurtimeto a string before you concatenate it to the result.