Hi,
I am trying to convert a string length to a char and store it in an array. For some reason, even though its not giving me any error, when I try to print the array out, the place where I store the strlen is blank. Here's my code:
int main () {
char host[] = "www.google.com";
char delim[]=".";
int i=0, index=0;
char *token;
char buf[100];
unsigned char len_char;
int length;
token = strtok(host, delim);
while (token != NULL) {
length = strlen(token);
len_char = (unsigned char) length;
printf("%c", len_char); //<----this does not print anything too!!
buf[index++] = length; //add the length as the beginning of a string
//printf("here%c", buf[index++]);
for(i=0; i<length; i++) {
buf[index++] = token[i];
//printf("%c", buf[index++]);
}
token = strtok(NULL, delim);
}
printf("%d, %s\n", strlen(buf), buf);
return 0;
}
The output I get is as follows:
15, wwwgooglecom
where as I am expecting something like:
15, 3www6google3com
Please note that the strlen(buf) gives the expected result. It's just that the numbers are not printed. Any help would be appreciated. Thanks.
-lilpro