Ez ... right? Has't to do with arrays being null'd

This is a discussion on Ez ... right? Has't to do with arrays being null'd within the C Programming forums, part of the General Programming Boards category; I have been useing this to make every array subscript null ... Code: char str[80]; int idx; for( idx = ...

  1. #1
    0x01
    Join Date
    Sep 2001
    Posts
    88

    Ez ... right? Has't to do with arrays being null'd

    I have been useing this to make every array subscript null ...

    Code:
    	char str[80];
    	int idx;
    
    	for( idx = 0; idx < strlen(str); idx++ )
    		str[idx] = NULL;
    Isn't there a better way? Yes, yes i know i can make my own function out of that, but I would like to force every subscript of the array to be null once it(char array) is declared ... ? TIA.

  2. #2
    KeM
    KeM is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    3

    jupp

    memset( void *data, int value, sizeof( data ))

  3. #3
    0x01
    Join Date
    Sep 2001
    Posts
    88
    KeM, good function and thanks for your time... but..

    I want all of the subscripts to be NULL as the array variable is declared ...
    For Instance :
    Code:
    char string[80] = want all the subcripts to be NULL right here.
    TIA.
    Last edited by knave; 02-14-2002 at 03:24 PM.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    char string[80] = {0};
    But be warned, this will flag warnings on some compilers and most definitely lint. Something along the lines of assigning an int where a char is expected and not specifying more than one element in an array of 80. But in this initialization if you don't specify all of the elements then the ones you didn't specify will be set to NULL by default.

    I'd suggest you use memset instead though.

    -Prelude
    My best code is written with the delete key.

  5. #5
    0x01
    Join Date
    Sep 2001
    Posts
    88
    Ok, cool. Thanks to all who responded (KeM,Prelude). I have managed to take in memset, works perfectly. later.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 03:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  3. My Arrays!!!, My Arrays!!! Help!?
    By llcool_d2006 in forum C++ Programming
    Replies: 1
    Last Post: 12-10-2006, 11:07 AM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 09:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

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