I have a program that's supposed to read in a file with comma seperated values. This file contains duplicates. The goal is to write a new file that does not contain any of the duplicates. I've successfully written the code to read in a file and create a new, identical file, but I'm failing at deleting the duplicates.
The format of each line in the file is: index,first_name,last_name,address,city,state,zip_code
This code writes the file I want (overlooking the duplicates) if I implement my equality operator as follows:
bool operator ==(const Person &a, const Person &B)/>
{
return false; //placeholder
}
Obviously this doesn't get the job done, since it will never detect a duplicate. The problem is that whenever I try to write any meaningful code, the program writes an empty file. The idea I've been trying to implement is to compare each of the members of Person like this:
bool operator ==(const Person &a, const Person &B)/>
{
//if two Person objects have equivalent names, they are duplicates
return ( (a.first_name == b.first_name) && (a.last_name == b.last_name) )
}
At first I thought the program was working just as before, but then deleting each line of the file as the result of an error in my code. However, I tried troubleshooting the problem by adding in
cout << a.last_name;
to parts of my code so I could see the value in certain places. Whenever I add this line or try to access a member of Person, the program writes a blank file.
I currently have a .csv file that should only contain numerical values however there are errors in some columns that mean there is text included. I am wondering what the best way of going about removing these characters would be.
I am looking at using : str.erase(std::remove(str.begin(), str.end(), 'xxxxxxx'), str.end());
For this I will need to read my data into a string and then remove the alphabet from that string. I am currently doing this like so (I use the '?' as a delimiter because I know there are none in my file).
I would like to extract and analyse the data but the data behind the NUL entry is not accessible for me maybe due to the fact that NUL normally marks the end of a line. Is there a method to remove the NUL entries in this text file?
this is the code I tried in my code block 10.05.....tried code for removing all white space from a line of a txt file. this is my code it runs but i cant get the result i need.
Code: /* generals is the first array. Max 10 elements. numGenerals is the element count of generals.
genBuff is the second array; it is to be checked/pruned. genCount is the element count of genBuff. genBuff will be a max of 171, but be pruned to no more than 10, and no more than the complement of the element count of generals. */
[Code] ....
(I do have comments in the actual source, different from above).
I have two int arrays. They hold values from 0 to 170. The first one will never be more than 10. The second will be at most 171, but will be whittled down to at most 10, usually less. 171 is worst case, most users of this particular program will probably be reasonable and not try to add all 171 (max is 10 anyway). The first array is the original array. The second array is a temporary array. Any value in the second array that is also found in the first array, is removed from the second array, since all values in the first one must be unique. After this pruning process, both arrays will collectively contain no more than 10 unique elements; the elements from the second will be added to the first.
So right now I have three nested loops. I figured with the miniscule array sizes it wouldn't be a big deal. I can think of a way to remove one or two of them, but I want to be sure that I'm still writing clean, legible, good-practice code. The first loop walks through the first array. For each element in the first array, there is a second loop to walk through the second array to check for duplicates. If a duplicate is found, the third loop walks through the second array to overwrite the duplicate while preserving the second loop's position (j).
Is this dumb? I know that the big O gets worse and worse the deeper you go with nested loops. Even though the arrays are really tiny, is this still a thing to avoid?
bool HashTable::insert(char const * const key, const Player& aPlayer) { //calculate the insertion position (the index of the array) size_t index = calculateIndex(key); for(int i=0; i < capacity; i++) {
[Code] ....
The inserting part works just fine, but the checking for duplicates where I compare the two values is crashing my program.
I want to create a randomly ordered array of integers where there are no duplicates. Is there a way of doing this in one iteration? Or maybe even a standard function for this?
I'm looking for something like this: A2 = [3 2 1 6 7 8 4 5]
I'm having some trouble printing the duplicates found in an array. Specifically, when the value is at more than 2 positions. So if the value 3 is at position 1, 10, and 11 it'll print three messages instead of two:
value 3 at position 1 is also at position 10 value 3 at position 1 is also at position 11 value 3 at position 10 is also at position 11
instead of
value 3 at position 1 is also at position 10 value 3 at position 1 is also at position 11
This is real simple problem, but I can't seem to figure it out. I've been trying to implement another array to 'remember' the encountered position, but I haven't had any luck.
Code: for(i = 0; i < num_count; i++){for (j = i + 1; j < num_count; j++) {if (num[i] == num[j]){printf(" value %d at position %d is also at position %d", num[i], i, j);}}}
I have same question as posted by holla and Iam not sure about merging the contents of 2 sorted arrays into another array without duplication of values.
I need to remove the duplicates but each part of the vector corresponds to the next location. They are pairs.
ex. bob corresponds to the its definition, which is sam.
I need to keep the first instance, so keep bob and sam, but remove the second instance of bob, so remove bob and sammon. Only the first instance of the pair need to kept.
It doesn't matter if the sam and sammon don't match, all that matters is the first part of the pair.
The vector is already in alphabetical order. I can't use the algorithm library.
I have a text file that needs to be read by command line arguments. The text are all numbers and can have multiple numbers on one line separated by a space. I cannot use an array or sort the numbers.So say I have a text file, listNums.txt:
12 473 8 29 30 1 8 248 17 55 29 84 5
Basically I need to read one number, find out if its odd or even by dividing by 2, search the odd or even doubly linked list that it would go into to see if its in there, if its not then add it to the bottom of the list.
I'm supposed to create a program that stores names and then the final function is supposed to remove a name. But it only removes the first name instead of the inputted name.
the problem with names.erase(names.begin()+i)?
#include <iostream> #include <string>//include for string function #include <vector>//include for vectors
I'm having a problem with removing an item from a queue. At first in the debugger I got SIGTRAP but I don't get it anymore but the problem still exists. When you try to remove an item from the queue the first nothing happens. Here's the code below compile it and you see what I'm talking about.
This has the effect of removing the dots but keeping the length of the string the same, so old characters are left over at the end. Is there an extra action to do to x to make it the right size or is there a better way of doing it?
I'm working on a problem in which I've to design a program in which the punctuations should be removed from the string. For eg., if input str is: "Hello!!"; the output must be: "Hello".
I'm not sure how to remove a sub-string (if that's the right word!!) from a string. So, I designed a program which print out the punctuations. For eg., if input str is: "Hey!!"; the output would be: ! !
Here it is:
#include <iostream> #include <string> using namespace std; int main (){ cout << "Enter a string" << endl;
[Code] ....
So, I want to know what should be added to this program so that the punctuations can be removed; or should I rewrite another program for that?
I'm working on creating a windows form with a listbox, textbox, and 2 buttons (add,remove). I need a way of removing every string matching the contents of the textbox from the listbox. Here's what I have:
for (int i=0;i<listBox1.Items.Count;i++) { //... listBox1.RemoveAt(i--) }
Seems to work, but I need a way to show a error message once the user clicks 'remove' and no items in the listbox match.
im working on a homework assignment t that should print all pairs of integers that sum to val. I have so far finished except It prints duplicate values (ie (3,1) and(1,3) for values that add to 4) . how can i remove these duplicate pairs of values?
#include <iostream> #include <map> #include <vector> using namespace std; void printPairs( vector<int> numbers, int val){ int i;
I'm trying to remove the title bar from an external app. The reason is I don't want anyone to be able to move it.
But my code below doesn't remove the title bar. Could this be because it's not removable? I read somewhere title bars of external apps may be not removable if the app doesn't allow it.
So, I'm not sure why my code doesn't work - either it's wrong or the app doesn't permit it?
I am having a problem with the output of a file. My function does everything it needs to do with the exception of one line. I have a .dat file with the following:
Code: joe clint james brint howard jimmy alexander * me
When I run the function my output is as such:
Code: file opened word: joe digit: 3 word: clint digit: 5 word: james
[Code] .....
ERROR non alphanumeric digit on line 4!
File closed "Howard" is only six digits in length. Also it seems to skips a line in the output which could be the extra character but I am not sure. What I find very interesting is the other names, (jimmy & alexander) on separate lines do not have that problem.
Here is my function:
Code: #include "main.h" #include "fileCheck.h" int fileCheck(FILE *fp){
int line_count = 0; int ret_val = 0; int digit_count = 0; char file[BUFF];
[Code] .....
How I can correct this? I am aware of sscanf to parse the line but I do not know the format of the file. All I know is the file will be alphanumeric and if there is a non-alphanumeric, I must print out an error with the line it occurred on such as the above output.