I made a program to delete duplicates in an array but the program's if condition always remain true.
I understood what the problem was,changed arr[i] to arr[count] and allocated memory via malloc,but ... |
I'm new in c. I want to create array, and after it delete it, and then put another array into it. How can I do it? Thank u.
|
As in: How do you recover the memory, and delete the array to such an extent you can initialize it again later in the program? Like so:
char * array[][2] = {
{"bla","bla","bla"},
{"blabity","blabity","bla"}
}
// ...
|
|
In article , Martin T. <0xCDCDCDCD@gmx.atwrote: >Hi all! > >char* p = new char[n]; // POD! >... >delete[] p; // std compliant >delete p; // will work on VC8 >free(p); // will also work on VC8 > > >I am interested on which platforms/compilers the second two statements >would not work. (access violation or mem-leak). Philosophically, the question is somewhat interesting ... |
|
Hi All, I am coding as below. int *x = new int[10]; int * y= x; ............ ............. del [] y; x=NULL; When we are freeing the array, it should free the all memory locations corresponding to all elements. The compiler stores the number of elements of array, and releases the memory accordingly. So If we use del [] y; Does ... |
|
|
Hi, im pretty new to this so plz cut me some slag ;-) anyhow, i need to delete an array, or what i really need is to increase the array size, i was think i could be done by copying the array into a temorary array of the same size, then delete the original, initiate the old array again, but now ... |
{ printf("Enter Which # you would like to Delete: "); scanf("%d%c", &delete,&cDump); printf("Enter Upto where (Enter same number to delete 1 number): "); scanf("%d%c",&deleteto,&cDump); if ((delete>i&&deleteto>i)&&(delete>i&&deletetostructRecipe.steps[delete-1].step[0]='\0'; while(pMod->structRecipe.steps[delete].step[0]!='\0') { strcpy(pMod->structRecipe.steps[delete-1].step,pMod->structRecipe.steps[delete].step); pMod->structRecipe.steps[delete].step[0]='\0'; delete++; } } else { for(x=delete;x<=deleteto;x++) { pMod->structRecipe.steps[x-1].step[0]='\0'; space++; } while(space!=0) { while(pMod->structRecipe.steps[delete].step[0]!='\0') { strcpy(pMod->structRecipe.steps[delete-1].step,pMod->structRecipe.steps[delete].step); pMod->structRecipe.steps[delete].step[0]='\0'; delete++; space--; } } ... |
|
#include #include int main ()/*void main() can also be used , depends unpon programmer*/ { char name[]="under test"; int marker=2,count,string_length=strlen(name); /*now suppose we remove 'd' from under test*/ for(count=marker;count |
Well, you're probably going to have to shift everything down by one position in the array starting just after the item you wish to delete. Also, if there is no way to tell where the end of the array is you'll need to have another variable that indicates the current size of the array. With character strings this isn't that important ... |
I write a maximum independent set algorithm, when I try to do memory management, I got seg fault. Inside the createTree() method, the last 6 lines, I try to delete array that I wont use. It give me a seg fault. Look for the line with ************* in my code Code: #include #include #include //for atoi() #include #include #include using namespace ... |
|
Hi, I have a little problem. I have a buffer structure, it is filled with numbers that come from a scanner read. When I have finish with one item or 2 or 3, I would like to remove them from my buffer, and that my N th item become my first item in my buffer. How could I do this ? ... |
|
hi, anyone can tell me how to delete data inside array? i've integer array's,array[0] to array[4] that contains value 3. then i want to delete the value inside array[2] into NULL. so when i print it, it'll show "33NULL33". r there any way to to this? i've try to use free(), but it still print out "33333". |
Hello; I have a structure and i want to output authors. But some authors dublicates. How to remove dublicated authors from array? ============================ Skema Miskas 1978 Lietuva tolstojus Karas ir taika 1982 Rusija Skema blabla 1974 Latvia ============================ //--------------------------------------------------------------------------- #include #pragma hdrstop #include #include #include #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall ... |
This is akin to insertion sorts, which should be covered in data structure textbooks and on-line tutorials. Basically, if you have n valid pointers in your array and the one you want to delete is at index i, then: delete the object being pointed to by the i'th pointer. write a for loop that will copy all the valid pointers to ... |
I am writing a genetic simulation program, am fairly new to C, and especially new to using pointers. My problem is working with an array of lists. I've successfully added elements to each list within the array, but have only been able to delete elements if they are not the first in the list. The program compiles fine, but crashes as ... |
In an array, that's about the size of it. Of course, you can do it in a for-loop, so coding it is not so painful: Code: /* index is the index of the item to be deleted ARY_SIZE is the array size; indices run from 0 to ARY_SIZE-1 */ for (i=index; i < (ARY_SIZE-1); i++) ary[i] = ary[i+1]; And to insert ... |
|