MESSAGE
DATE | 2004-04-22 |
FROM | Ruben Safir Secretary NYLXS
|
SUBJECT | Re: [hangout] Debugging cdparanoia in C
|
sizeof also works with structs and arrays. (a string is an array of chars)
1 #include 2 #include 3 4 int main(int argc,char **argv ){ 5 char buffer[] = "My Dog Has Fleas!"; 6 char * buf2; 7 int size = 0; 8 size = sizeof(buffer); 9 printf("Size of Buffer is %i\n", size); 10 printf("Buffer is %s\n", buffer); 11 buf2 = (char*)malloc(255); 12 size = sizeof(buf2); 13 printf("Size of Buffer is %i\n", size); 14 strncpy(buf2, buffer, 5); 15 size = sizeof(buf2); 16 printf("Size of Buffer is %i\n", size); 17 printf("Buffer is %s\n", buf2); 18 exit(1); 19 }
./a.out
Size of Buffer is 18 Buffer is My Dog Has Fleas! Size of Buffer is 4 Size of Buffer is 4 Buffer is My Do
The puzzle here is that sizeof seems to not work with the char pointer. I'm not happy about that. I wonder how it behaves with strings passed as params. It probibly doesn't.
Ruben
> > sizeof(s) ==> sizeof(char*) ==> 4.
-- __________________________ Brooklyn Linux Solutions
So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://fairuse.nylxs.com
http://www.mrbrklyn.com - Consulting http://www.inns.net <-- Happy Clients http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive or stories and articles from around the net http://www2.mrbrklyn.com/downtown.html - See the New Downtown Brooklyn....
1-718-382-0585 ____________________________ NYLXS: New Yorker Free Software Users Scene Fair Use - because it's either fair use or useless.... NYLXS is a trademark of NYLXS, Inc
|
|