c - 无法在输出中显示时钟

标签 c

<分区>

要在 strcat 之后使用时钟函数生成毫秒,但它只是崩溃,可能是什么问题?

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;

最佳答案

asc 的赋值非常可疑:

double *asc = (double *) curtime;  //Using double datatype?

您可以测量两个 clock() 值之间的差异,以确定使用的处理器时间。

您可能会获得更接近成功的结果:

double asc = curtime;

strlen() 操作未定义 - 在 asc 的任一定义下:

strAll = (char *)malloc(strlen(temp) + strlen(str) + 1 + strlen(asc) + 1);

然后 strcat() 操作将严重失败;您必须先将 double 转换为字符串,然后才能将字符串连接到另一个字符串。

strcat(strAll,(char *)asc);  //Is this correct?

所以,你有很多工作要做。您需要确定 clock() 是否是正确的系统调用。如果是,则在将其连接到结果之前,您必须修复 asccurtime 的大小和转换为字符串。

关于c - 无法在输出中显示时钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8651270/

相关文章:

c - 使用 fscanf 接收数组

c - 为什么尝试编译 SDL 时链接器出错?

c - C语言输出中倒置的问号是什么意思?

c - C中静态函数和非静态函数的区别

Android NDK/JNI UnsatisfiedLinkError With .So library

c - 要么我的二进制文件未填充,要么我无法从中读取

c - 制作通用函数将项目加载到链接列表中

c - 如果链接到它们的 fd 用于其他目的,FILE * 是否继续工作?

需要最少样板的 C 跨平台 RPC?

c - 循环 n-1 次而不是 n 次。为什么?