how to make one all elements of array be equal to '

This is a discussion on how to make one all elements of array be equal to '

Thread: how to make one all elements of array be equal to '\0'?

'?
within the C Programming forums, part of the General Programming Boards category; how to make one all elements of array be equal to '

Thread: how to make one all elements of array be equal to '\0'?

'? Code: char a[10]; for ( int i = ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    168

    how to make one all elements of array be equal to '\0'?

    how to make one all elements of array be equal to '\0'?

    Code:
    char a[10];
    for ( int i = 0; i < 10 ; i++ )
          a[i] = '\0';
    Is there more easier methond to process this job?

  2. #2
    Registered User
    Join Date
    Sep 2009
    Location
    USA
    Posts
    63
    yes there is.

    this works

    char a[size]={'\0'};
    Last edited by Obelisk; 12-25-2009 at 09:38 PM.

  3. #3
    Registered User
    Join Date
    Dec 2009
    Location
    Bangalore, India
    Posts
    1

    how to make one all elements of array be equal to '\0'?

    Hi

    Use memset function.

    Regards,
    Vaisakh P S

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Obelisk View Post
    yes there is.

    this works

    char a[size]={'\0'};
    Use this method if you want to initialize them all to '\0'.

    Quote Originally Posted by vaisakhrulez View Post
    Hi

    Use memset function.

    Regards,
    Vaisakh P S
    Use memset() if you want to reset them all to '\0'.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    I see!
    Thank you for your replys

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by vaisakhrulez View Post
    Use memset function.
    Memset is just a loop wrapped in a function call. So in a way it's "easier", because you don't have to type out the loop, but in reality, it's pretty much identical do doing it yourself.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screen output of array elements
    By Lego_TeCh in forum C Programming
    Replies: 4
    Last Post: 07-26-2009, 11:51 AM
  2. Multidimensional Array Addressing
    By BlackOps in forum C Programming
    Replies: 11
    Last Post: 07-21-2009, 10:26 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-12-2004, 12:15 AM
  5. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM