include function prototype void deleterepeats char aint po
#include <iostream>
// function prototype
void delete_repeats (char a[],int & positions_usd);
bool find_char (char target,char a[], int size);
int main()
{
char a[81]=
\"mary had a little lamb. its fleece was white as snow. \";
int size= 53;
cout << \"Before : size= \" << size <<endl;
for (int i = 0 ; i < size ; i++)
{
cout << a[i];
}
cout << endl;
// function call
delete_repeats(a,size);
cout << \" After : size=\" << size << endl;
for (int i=0;i < size ; i++)
{
cout << a[i];
}
cout << endl;
// pause system for a while
return 0;
}
bool find char (char target, char a [], int size)
{
for (int i=0; i<size ; i++)
{
if (a[i]== target)
return true;
}
return false;
}
// delete repeat character from a []
void delete_repeats(char a[],int & positions_used)
{
int new size =0;
for (int i=0; i< positions used; i++)
{
if (!find _char(a[i],a,new_size))
{
a[new_size]=a[i];
new_size++;
}
}
position_used = new_size;
}
}
i have a error at like 13 and 32
Solution
THE WORKING CODE
#include <iostream>
// function prototype
using namespace std;
void delete_repeats (char a[],int * positions_usd);
bool find_char(char target,char a[], int size);
int main()
{
char a[81]= \"mary had a little lamb. its fleece was white as snow. \";
int size= 53;
cout << \"Before : size= \" << size <<endl;
for (int i = 0 ; i < size ; i++)
{
cout << a[i];
}
cout << endl;
// function call
delete_repeats(a,&size);
cout << \" After : size=\" << size << endl;
for (int i=0;i < size ; i++)
{
cout << a[i];
}
cout << endl;
// pause system for a while
return 0;
}
bool find_char (char target, char a [], int size)
{
for (int i=0; i<size ; i++)
{
if (a[i]== target)
return true;
}
return false;
}
// delete repeat character from a []
void delete_repeats(char a[],int * positions_used)
{
int new_size =0;
for (int i=0; i< *positions_used; i++)
{
if (!find_char(a[i],a,new_size))
{
a[new_size]=a[i];
new_size++;
}
}
*positions_used = new_size;
}
OBTAINED OUTPUT
Before : size= 53 mary had a little lamb. its fleece was white as snow. After : size=19 mary hdliteb.sfcwno
NOTE: The code was having problem in pointers, some variables names are not used properly after decleration, one extra } in last function, missing \"using namespace std;\" etc..
![#include <iostream> // function prototype void delete_repeats (char a[],int & positions_usd); bool find_char (char target,char a[], int size); int mai #include <iostream> // function prototype void delete_repeats (char a[],int & positions_usd); bool find_char (char target,char a[], int size); int mai](/WebImages/15/include-function-prototype-void-deleterepeats-char-aint-po-1024319-1761530145-0.webp)
![#include <iostream> // function prototype void delete_repeats (char a[],int & positions_usd); bool find_char (char target,char a[], int size); int mai #include <iostream> // function prototype void delete_repeats (char a[],int & positions_usd); bool find_char (char target,char a[], int size); int mai](/WebImages/15/include-function-prototype-void-deleterepeats-char-aint-po-1024319-1761530145-1.webp)