Thread: any way to determine size of array thats a function parameter?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    1

    any way to determine size of array thats a function parameter?

    Hi, I have a function that accepts as its argument a pointer to a character array, and writes some values to it.

    i'd like to check the size of it (the number of elements) to make sure I don't overwrite past its boundaries

    Something like: sizeof(array)/sizeof(char) only works if the code is executed in main and the array is declared inside of main

    sizeof(array)/sizeof(char) does not work inside a function, because the compiler treats the passed in array as a pointer, and returns the size of the pointer, not the array.

    Any ideas?

    Note: I'm not using strlen because I want to check the actual size of the array, not the length of the string.
    Last edited by fishjie; 12-14-2004 at 05:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing multidimensional/dynamic array to function
    By epyfathom in forum C Programming
    Replies: 2
    Last Post: 04-02-2009, 05:39 PM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. dynamically defined array size in a function
    By earth_angel in forum C Programming
    Replies: 21
    Last Post: 05-28-2005, 01:44 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM