Thread: Deleting data from a structure?

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    22

    Deleting data from a structure?

    I have a stucture of arrays that holds data such as member number, videonumber,and rental date.

    How would i go about deleting from the structure one of these records?

    BlueBob

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Highlight the line that the member is declared on and hit the delete key. You can't delete a structure member at runtime, you can only clear the values that the member holds.

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

  3. #3
    Registered User lliero's Avatar
    Join Date
    Oct 2001
    Posts
    59

    Cool right

    prelude is right...


    but if i'll try to analyze you problem, i think you want to
    delete tha value in those member variables




    the problem with you is that you did not specify your structure
    so take a look at this


    struct name{
    char employee[80];
    int sex;
    }age;

    main(){
    age.employee[0]=NULL;
    age.sex=0;
    }


    i am not quite sure if this is ok with the other guys from this board..
    " programming is 1% syntax and 99% logic "

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >age.employee[0]=NULL;
    This is the only part that chafes with me. Despite what some may tell you, NULL and NUL are not interchangeable. So if you want to clear the array by making everying inaccessable to string based functions, this would be better:
    age.employee[0] = '\0';

    Though if you want to clear the entire array, memset would be your best bet:
    memset ( age.employee, '\0', 80 );

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

  5. #5
    Registered User lliero's Avatar
    Join Date
    Oct 2001
    Posts
    59

    Talking seee

    see i told you, this guys are really cool
    they always have the best idea...

    this site is the best site so far as far as c is concern


    to bluebob

    next time, read what you ask so that you'll get the right answer..

    tnx
    " programming is 1% syntax and 99% logic "

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Prelude
    >age.employee[0]=NULL;
    This is the only part that chafes with me. Despite what some may tell you, NULL and NUL are not interchangeable. So if you want to clear the array by making everying inaccessable to string based functions, this would be better:
    age.employee[0] = '\0';

    -Prelude
    MSVC++ does not recognize the keyword 'NUL'. The decimal value of 'NULL' is zero. It's the same thing as doing:

    age.employee[0] = 0;

    In either case, your compiler treats 'NULL' as 0 and the end result is the same. There is no standard definition of the word 'NUL' in C. This is an ASCII definition if I recall correctly. NULL is commonly defined as '\0'. Again, this has the same decimal value as 0.

    However, I see the point you are trying to make.

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

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >MSVC++ does not recognize the keyword 'NUL'.
    I don't know of any others that do, I imagine it would be too confusing to have a one L nul and a two L null used in similar contexts.

    >The decimal value of 'NULL' is zero.
    Only in some cases, here is a snip from stdio.h for MSVC++
    /* Define NULL pointer value */

    #ifndef NULL
    #ifdef __cplusplus
    #define NULL 0
    #else
    #define NULL ((void *)0)
    #endif
    #endif
    >In either case, your compiler treats 'NULL' as 0 and the end result is the same.
    Once again, not always and you can't be sure. So it's better to only use NULL for pointers and to specify '\0' explicitly or define it for a nul.

    >This is an ASCII definition if I recall correctly.
    Yes, NUL is 0x00(hex) or 00(oct) in the ASCII table.

    >NULL is commonly defined as '\0'. Again, this has the same decimal value as 0.
    In this case I believe you're wrong, the standard headers that I've seen are all similar to the one I quoted above. While I can agree with you to some extent that NULL is defined as 0, it's in such a way that you still should be very wary of using it as a simple decimal value.

    >However, I see the point you are trying to make.


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

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    I am re reading "The C++ Lang by Bjarne Stroustrup" And he actually recomends not to use NULL at all unless you define it yourself. He recomends to always use 0.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. static data structure in a library
    By melight in forum C Programming
    Replies: 6
    Last Post: 01-10-2009, 11:12 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Dynamic Data Structure -- Which one is better?
    By Yin in forum C++ Programming
    Replies: 0
    Last Post: 04-10-2002, 11:38 PM