|
|
![]() |
|
|
Top | #1 |
|
format c:
Joined: December 2002
Location: Southern California
Posts: 1,358
Reputation: 50
Power: 129 |
i assume setting it like this will delete. for strings: string_var = (""); for ints: int_var = (); -- but this doesn't work, neither does NULL for char: char_var = ('') or is there a way to delete AN ENTIRE LINE based on ONE array var matching the search, and putting in that array's location? ie: search for "Michael" found "Michael" in first_name[46] delete the entire line or everything related to [46] i already know that once its deleted from memory, i can just Loop the array and send that information to an open file for export. |
|
|
|
|
|
Top | #2 |
|
Godlike!
Joined: February 2004
Location: Salisbury, Wiltshire, UK
Posts: 7,031
Blog Entries: 5
Reputation: 4137
Power: 213 |
Its ineffecient but why not move everything else up a line or set [46] to \r\n?
|
|
|
|
|
|
Top | #3 |
|
format c:
Joined: December 2002
Location: Southern California
Posts: 1,358
Reputation: 50
Power: 129 |
sorry, google'd \r and couldnt find what it does and wouldn't know how to execute that option properly
|
|
|
|
|
|
Top | #4 |
|
Godlike!
Joined: February 2004
Location: Salisbury, Wiltshire, UK
Posts: 7,031
Blog Entries: 5
Reputation: 4137
Power: 213 |
\r = carriage return
\n = line feed should be in your c++ documentation and manual
|
|
|
|
|
|
Top | #5 |
|
format c:
Joined: December 2002
Location: Southern California
Posts: 1,358
Reputation: 50
Power: 129 |
i cant set an integer to that. but thanks for the suggestion. i'll remember that for later.
|
|
|
|
|
|
Top | #6 |
|
Godlike!
Joined: February 2004
Location: Salisbury, Wiltshire, UK
Posts: 7,031
Blog Entries: 5
Reputation: 4137
Power: 213 |
you're making an array right?
The file will contain alpha-numeric characters right? You can set an array of strings to \r\n... What do they teach you in c++ class these days?? This is obivous to me with my limited self-taught c++ knowledge.... |
|
|
|
|
|
Top | #7 |
|
format c:
Joined: December 2002
Location: Southern California
Posts: 1,358
Reputation: 50
Power: 129 |
maybe i f'd up. i made fname, lname, and scores my array. scores is a two-d array of scores for each person and then the individual scores are arrays also.
so when i delete, i need to clear the (string) fname, (string) lname and (int) scores i can send you the code if you want.. its ~ 18 pages but i everything is in functions. |
|
|
|
|
|
Top | #8 |
|
Godlike!
Joined: February 2004
Location: Salisbury, Wiltshire, UK
Posts: 7,031
Blog Entries: 5
Reputation: 4137
Power: 213 |
don't c++ arrays have delete functions anyways? sort of like int_array[12]->delete(); ???
|
|
|
|
|
|
Top | #9 |
|
*
Joined: December 2001
Location: USA
Posts: 6,496
Reputation: 2808
Power: 220 |
Ehm, no.
Please attach the code in this thread so we may take a look at it, as currently you are talking giberish to me!
|
|
|
|
|
|
Top | #10 |
|
OSNN Veteran Addict
Joined: March 2002
Location: United Kingdom
Posts: 7,805
Reputation: 1490
Power: 217 |
If this is C++ why don't you just read the file into a vector or something.
TextMate even has a snippet for doing just that ![]() Code:
std::vector<uint8_t> v;
if(FILE* fp = fopen("filename", "r"))
{
uint8_t buf[1024];
while(size_t len = fread(buf, 1, sizeof(buf), fp))
v.insert(v.end(), buf, buf + len);
fclose(fp);
}
another way might be to read the file in, checking for the data you want to remove each time and if you come across that then dont add it to the vector. or write the data out to another file as soon as you get it in and then not write out the data you dont want. |
|
|
|
|
|
Top | #11 |
|
format c:
Joined: December 2002
Location: Southern California
Posts: 1,358
Reputation: 50
Power: 129 |
@Geffy: That is too advanced for me. I can read the code but I dont know how to use it.
Code:
switch (catchRecord)
{
case'a':
cout << "\n\n\t\tNo Records to delete.";
break;
case'b':
cout << "\t\tPlease choose Record # to delete:\t";
cin >> delRecord;
cout << "\t\tAre you sure you want to delete:\n";
cout << fname[delRecord -1] << " " << lname[delRecord -1] << "\n";
cout << "Y or N\t" << endl;
cin >> delRecCheck;
if ((delRecCheck == 'y') || (delRecCheck == 'Y'))
{
fname[delRecord -1] = ("");
lname[delRecord -1] = ("");
// score[delRecord -1] = ();///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
ps: how do you post code and maintain indentation? |
|
|
|
|
|
Top | #12 |
|
*
Joined: December 2001
Location: USA
Posts: 6,496
Reputation: 2808
Power: 220 |
Originally Posted by dubstar
->delete() does not exist and thus will not work.
You post code with indendation by using spaces instead of tabs in the source code. |
|
|
|
|
|
Top | #13 |
|
OSNN Senior Addict
Joined: January 2004
Location: Houston, Tx
Posts: 303
Reputation: 359
Power: 109 |
Originally Posted by LordOfLA
You can remove information from within an array through the use of delete.
delete arrayName[index] There are probably other ways to do it. That's what I use to remove items from my dynamic arrays. |
|
|
|
|
|
Top | #14 |
|
Penguin Rancher
Joined: February 2002
Location: Elizabethton, TN
Posts: 280
Reputation: 180
Power: 129 |
The delete directive in C++ deallocates memory. It does not remove information from the array.
In order to "delete" that item from the array, you can just copy over it with the next element from the array. Doing that repeatedly through the end of he array and decrementing your counter tracking the number of elements in your array should suffice. For example, imagine you have an array with 3 elements and a counter for num elements. [0] = 1 [1] = 2 [2] = 3 nElements = 3; If you wanted to remove value 2 at index position one, you could just copy the next element in the array down a value and decrement nElements. [0] = 1 [1] = 3 nElements = 2; Once you have the array in the state you want, you can just rewrite the output file with the current contents of the array(s). |
|
|
|
|
|
Top | #15 |
|
Penguin Rancher
Joined: February 2002
Location: Elizabethton, TN
Posts: 280
Reputation: 180
Power: 129 |
An example.
Code:
int *iPtr = new int[5]; // allocate memory
int nCount=5; // set num of array items
int nChoice=0; // variable to hold user index choice
for(int nI=0;nI<nCount;nI++) // loop and generate values for array
iPtr[nI]=nI;
for(int nI=0;nI<nCount;nI++) // display array contents
cout << "index " << nI << ": " << iPtr[nI] << endl;
// prompt user for index
cout << "Enter an index to delete: ";
cin >> nChoice;
// copy elements starting at delete index through count -1
for(int nI=nChoice;nI<nCount-1;nI++)
iPtr[nI]=iPtr[nI+1];
// decrement number of array items
nCount--;
// redisplay array contents
for(int nI=0;nI<nCount;nI++)
cout << "index " << nI << ": " << iPtr[nI] << endl;
|
|
|
|
|
|
Top | #16 |
|
Godlike!
Joined: February 2004
Location: Salisbury, Wiltshire, UK
Posts: 7,031
Blog Entries: 5
Reputation: 4137
Power: 213 |
I though there was an array class that let you delete entries and did the recursive move up for you, must have been a different language.
My c++ knowledge is limited anyway so don't go interpreting my posts as the right way to do things and more as ideas in the direction to search around and look in various documentation sources. |
|
|
|
|
|
Top | #17 |
|
Penguin Rancher
Joined: February 2002
Location: Elizabethton, TN
Posts: 280
Reputation: 180
Power: 129 |
The Vector class in the STL has a bunch of methods for manipulating containing data. You may have been thinking of that.
Arrays in C++ are very basic. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Group Policy, Legal Notice Text, Line break within? | Punkrulz | Windows Server Systems | 0 | December 8th, 2006 1:47pm |
| I need a program that generates a text file on all the file names and meta data | VenomXt | Windows Desktop Systems | 14 | August 26th, 2006 2:47am |
| Text file merge util | 762x51 | Windows Desktop Systems | 3 | June 27th, 2006 7:21am |
| The line seperating text + signatures | Unleashed | Site Problems & Feedback | 24 | September 7th, 2004 11:54pm |
| Text file encoding question | omega2 | Windows Desktop Systems | 2 | February 27th, 2003 6:44am |