Using Pointers to Remove Duplicates.
So I am having a hard time understanding how to alter my code..
the prompt is:
Return a new dynamic array where all repeated letters are deleted instead of modifying the partially filled array.
Was wondering if I could get any pointers.... haha, bad pun I know.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
using namespace std;
int length(char[]); //function determines length of array
int dele(char[], int);//function deletes duplicates
int display(char[], int);//function displays new array
//Description: The programs removes duplicate characters from an array.
int main()
{
int size; //size of array
//array
char *array[100] = "Have a nice day, and a wonderful weekend.";
size = length(array); //calling size function
cout << array << endl;
cout << "size = " << size << endl;
dele(array, size);//calling delete function
display(array, size);//calling display function
}
int length (char array[])
{
int i;
for (i=0; '\0' != array[i]; i++)
{
}
return i;
}
int dele(char array[], int size)
{
int i, j, k;
for(i=0; i<=size; i++)
{
for(j=i+1; j<=size; j++)
{
if(array[i] == array[j])
{
for(k=j; k<size; k++)
{
array[k]=array[k+1];
}
j=i;
size=(size-1);
}
}
}
cout << "Now the size is " << size << endl;
}
int display(char array[], int size)
{
int i;
for(i=0;i<size;i++)
{
cout<<array[i];
}
cout<<"\nThe program is over\n";
return 0;
}
|
Still looking for some help with this, thanks!
Topic archived. No new replies allowed.