字符串的长度为字符串

时间:2012-11-02 14:39:47

标签: c string string-length

  

可能重复:
  How to convert integer to string in C?

我想计算字符串的长度,并将值作为字符串传递给函数。

char* s="abcd";
int i = strlen(s);
char* lengthAsString = ????(i);

1 个答案:

答案 0 :(得分:4)

char* s = "abcd";
int i = strlen(s);
char lengthAsString[50];
sprintf(lengthAsString, "%d", i);

// now you can use lengthAsString to pass it to a function