0

Possible Duplicate:
How to convert integer to string in C?

I would like to calculate the length of the string and pass the value to a function as a string.

char* s="abcd";
int i = strlen(s);
char* lengthAsString = ????(i);
Community
  • 1
  • 1
dare2k
  • 417
  • 2
  • 8
  • 24

1 Answers1

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
Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
aakash
  • 751
  • 5
  • 18