Thread: Size of a string

  1. #16
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Lol. It works in MSVC 6.0. Yea, I know. It's outdated. Check out some code that runs with flying colors in MSVC 6.0. I apologize in advance for casting malloc.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <malloc.h>
    
    int main() 
    {
    	int *lpArray = (int*)malloc(sizeof(lpArray) * 101);
    
    	size_t sizeArray = _msize(lpArray) / sizeof(lpArray);
    
    	printf("lpArray has a size of &#37;d.\n", sizeArray);
    
    	return 0;
    }
    [edit]Ye Old Popular Search Engine[/edit]
    Last edited by Brad0407; 04-10-2007 at 06:46 PM. Reason: link
    Don't quote me on that... ...seriously

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ah, my font makes it look like it's all run together: "size_t_msize", which is why I didn't find anything on it.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #18
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    PellesC, LCC & LCC~Win32 have it in stdlib.h

    Code:
    /* private extensions to standard C */
    //...
    size_t __cdecl _msize(void *);

  4. #19
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I found it inside MALLOC.h for the Win32 version of LCC.

    Borland supports it, too, under malloc.h.

    Can anyone find a popular compiler that does not support it? I'd be interested in knowing how portable this is.

  5. #20
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Oh, I don't know...


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #21
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,674
    > I'd be interested in knowing how portable this is.
    The fact that it begins with an _ should tell you all you need to know about how useful that function is.

    Why is it so hard to store the parameter you passed to malloc in the first place in another variable?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #22
    Registered User
    Join Date
    Apr 2007
    Location
    patiala
    Posts
    1
    Try using
    strlen(String)

  8. #23
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by RakeshKhanna View Post
    Try using
    strlen(String)
    I suppose you didn't read the earlier posts?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  4. An exercise in optimization
    By Prelude in forum Contests Board
    Replies: 10
    Last Post: 04-29-2005, 03:06 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM