why does the following code crashes

This is a discussion on why does the following code crashes within the Linux Programming forums, part of the Platform Specific Boards category; Hi Friends, can anyone tell me why does the following code crashes void init (char** ptr, char initchar, int len ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    1

    why does the following code crashes

    Hi Friends,
    can anyone tell me why does the following code crashes

    void init (char** ptr, char initchar, int len )
    {
    memset ( *ptr, initchar, len );
    }


    void main()
    {
    char ary[10];
    init( (char**)&ary, 'b', 10 );
    }

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    because you sending a single dimensional array to a multi-dimensional pointer,

    do it as follows,

    Code:
    void init (char* ptr, char initchar, int len ) 
    { 
        memset (ptr, initchar, len ); 
    } 
    
    
    int main() 
    { 
        char ary[10]; 
        init(ary, 'b', 10 ); 
        return 0;
    }
    Last edited by no-one; 10-09-2001 at 12:30 PM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When your code crashes
    By caroundw5h in forum C Programming
    Replies: 9
    Last Post: 06-19-2004, 10:40 PM
  2. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  3. code crashes on Solaris
    By watcher in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2003, 07:58 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21