remove a chracter from array

i have to make a function which take an in put char array and a character and it have to remove first occurrence of that character in array.how to remove a selected character from array please help me???


#include<iostream>
#include<cstring>
using namespace std;
void delet(char*arr)
{
arr=new char[1000];

cin.getline(arr,1000);
strlen(arr);
int p=strlen(arr);
int temp[1000];
int j=0;
char c;
cin>>c;
for(int i=0;i<p;i++)
{
if(arr[i]==c)
{
temp[j]=i;
j++;
}

}

int m=temp[0];
//arr[m]=' ';
for(int i=1;i<p;i++)
{
if(arr[m]!=arr[i+1])
{
arr[m]=arr[i+1];
}
cout<<arr[i];
}

}
int main()
{
char*p=0;
delet(p);
}
Last edited on
i have to make a function which take an in put char array and a character and it have to remove first occurrence of that character in array.
Are you sure you mean array and not string?

If you mean array, then you also need to pass in the length. Also, you need to be clear about what you mean by remove.

If you mean string, then passing the char array is fine because we can work out the end, it's terminated by a null character. Also, remove from a string means move all the higher characters down by one.
Topic archived. No new replies allowed.