I want to allocate room in a buffer so I can send data through a socket (I've got to write a simple FTP program for class); however, every time I call malloc, it only allocates 4 bytes. I wrote some sample code to test it:
The output is:Code:#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char* buffer; buffer = (char*) malloc((size_t)sizeof("Sample string.")); printf("%d\n",sizeof(buffer)); printf("%d\n",sizeof("Sample string.")); free(buffer); return 0; }
Shouldn't they both say "15"? What am I doing wrong with malloc?4
15



LinkBack URL
About LinkBacks


