c++ help

0 lou graham · April 3, 2015
Help with c++ I am really new to c++ and I am working on a project that inputs chars in an array then deletes redundant chars?


I basically just need some advice on the logic to delete the redundant ones then replace them. I set up a new array c that would store the non redundant chars from array a then in output it. this is the function that I have been working on.

I already have a function to fill the array with characters from the keyboard (and I also put in some extra variable just in case i needed them) 


this is what I have so far, it breaks down in the logic in the delete_repeats function where I try to fill array c with non redundant chars from array a.    Also I am going to fix my functions after I get the logic done so that the print array function will also show array c.


#include <iostream>

const int MAX = 80;
using namespace std;
void fill_array(char a[], int size, int& actual);
void delete_repeats(const char a[], int& actual);
void print_array(const char a[], int& actual);

int main()
{
char b[MAX];
int actual;


fill_array(b, MAX, actual);
print_array(b, actual);


return 0;
}

void fill_array(char a[], int size, int& actual)
{
char in;
int i = 0;

cout << "Enter a character: ";

cin.getline(a, size);

actual = strlen(a);
return;
}


void delete_repeats(const char a[], int& actual) 

char temp; 
int x, y; 
char c[MAX]; //new array to store non redundant chars 
for(int i = 0; i < actual; i++ ) //first loop keeps the first char in place to compare against the rest of the chars 

for(int j = 0; j < actual; j++) //2nd loop set up to compare the first char to the rest of the chars in the array 

x = (j + 1); 

// this is the logic to store array c with non redundant chars from array a 
if ((j > i) && (a!= a[j])) 

c = a
c[j] = a[j]; 


if ((j > i) && (a == a[j])) 

do 

c[j] = a[x]; 
y = j; 
y++; 


while (y < actual); 






return; 
}



void print_array(const char a[], int& actual)
{
cout << actual << endl;
for(int i = 0; i < actual; i++ )
{
cout << a;
}
cout << endl;


delete_repeats(a, actual);

/*cout << actual << endl;
for(int i = 0; i < actual; i++ )
{
cout << a;
}
*/


return;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 lou graham · April 10, 2015
I just wanted to create a new array without all of the repeated characters
+1 ♦Avishka RJ ♦™ · April 3, 2015
:ninja: You want to delete something exist in the array and write something new. Am i right??   
  • 1

C++

107,170 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator