Struct problem

This is a discussion on Struct problem within the C++ Programming forums, part of the General Programming Boards category; Hi, How do write a function deleting 1 complete entry from this struct, like a mobile phone book code: __________________________________________________ ...

  1. #1
    totalfreeloader
    Guest

    Struct problem

    Hi,
    How do write a function deleting 1 complete entry from this struct, like a mobile phone book

    code:
    __________________________________________________

    struct Phone
    {
    long int number;
    char Name[Max + 1];
    }

    main( ) {
    struct Phone List[50] = {
    { 35387123456, Roy Keane }
    { 12345678890, Russell Cruise }
    };

    }
    _________________________________________________

    if i want to write a function which deleted on entry how do i do it?

    much appreciated

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    You cant really delete the memory in this array as it is stack based...You can overwrite it or set it to NULL, but you cant reduce the size of the array...

    If you want dynamic sizeing, then create elements on the heap....or use a container to do this (vector,list...)

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I wouldn't store phone numbers in a long int variable either. You'll loose any preceeding zeros amongst other things. For example, if the number is
    0800 123456
    when stored in an int, it would become 800123456
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    totalfreeloader
    Guest
    Thanks,
    Unfortunately I havent covered this and am new to it so how do i go about for example setting the second elements all to null?
    regards.....declan

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>setting the second elements all to null?

    List[1].Name[0] = '\0';
    ... will set the first element of the name array to NUL, giving you a zero length name string.

    List[1].number = 0;
    ... will set the number to 0.

    Neither of the struct elements are pointers, so you cannot actually use the term NULL.


    >>{ 35387123456, Roy Keane }
    The name needs to be in double quotes.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    totalfreeloader
    Guest
    thanks very much...much appreciated

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Struct File and array problem Please help
    By theprogrammer in forum C Programming
    Replies: 17
    Last Post: 04-02-2009, 08:05 AM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  3. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  4. Replies: 22
    Last Post: 12-23-2008, 12:53 PM
  5. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM

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