I have a similar kind of code as below. But I could not guess how to delete. Please help me.
[code=c]
#include<stdio. h>
#include<string .h>
#include<stdlib .h>
int main()
{
char* items[5];
int i;
for(i=0;i<5;i++ )
{
char* temp = new char[11];
strcpy(temp,"AB CD EFGH");
items[i] = temp;
printf("items is:%u\n",&items[i]);
printf("strlen of items is:%d\n",strlen (items[i]));
}
items[5] = 0;
char** item_ptr = items;
while (*item_ptr != 0)
{
printf("item_pt r is:%u\n",*item_ ptr);
delete *item_ptr; //whether this is correct?
//delete []*item_ptr; or this is correct?
item_ptr++;
}
return 0;
}
[/code]
Please let me know how to use the delete here. Thanks in advance.
[code=c]
#include<stdio. h>
#include<string .h>
#include<stdlib .h>
int main()
{
char* items[5];
int i;
for(i=0;i<5;i++ )
{
char* temp = new char[11];
strcpy(temp,"AB CD EFGH");
items[i] = temp;
printf("items is:%u\n",&items[i]);
printf("strlen of items is:%d\n",strlen (items[i]));
}
items[5] = 0;
char** item_ptr = items;
while (*item_ptr != 0)
{
printf("item_pt r is:%u\n",*item_ ptr);
delete *item_ptr; //whether this is correct?
//delete []*item_ptr; or this is correct?
item_ptr++;
}
return 0;
}
[/code]
Please let me know how to use the delete here. Thanks in advance.
Comment