-
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
-
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...)
-
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
-
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
-
>>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.
-
thanks very much...much appreciated