July 7th, 2003, 10:48 AM
sendbuffer is a char* pointing to the literal string "howdy". Or it could be viewed as the name of a char array, since array names and pointers are equivalent in C.
So when you do a sizeof(sendbuffer), you are getting the size of a char pointer, which is 4. Instead, you want the length of the string, which you get with strlen(sendbuffer). BTW, this will not include the null-terminator, but I don't think you'd need to send that.
Now, if instead you had explicitly declared a char array, then sizeof would have worked for you here. In a test program I just whipped up:
char s1 = "howdy";
char *s2 = "howdy";
printf("Size of s1 = %d\n",sizeof(s1));
printf("Size of s2 = %d\n",sizeof(s2));
The output was:
Size of s1 = 6
Size of s2 = 4
As you can see, sizeof on the array s1 returned the full size of the array, including the null-terminator.
Last edited by dwise1_aol : July 7th, 2003 at 10:59 AM.