I am new to the concept of character pointers and strings.So, having trouble in passing a string pointer and returning a string pointer in a function.the function is "remove".
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* remove(char* ,char ,int );
int main(){
int count, i;
char ch;
char* a;
char* b;
b=(char*)malloc(sizeof(char)*10);
a=(char*)malloc(sizeof(char)*10);
gets(a);
for(i=0;*a='\0';i++)
{
ch=a[i];
b=remove(&a[i],ch,i);
}
}
char* remove(char* str,char x,int k)
{
char* str2=(char*)malloc(sizeof(char)*10);
int i,j;
j=0;
int len;
len=strlen(str);
for(i=k;i<len;k++)
{
if(str[i]!='x')
{
str2[j]=str[i];
j++;
}
}
return str2;
}
The errors which i am getting are
error:conflicting types for 'remove'
In the line where the function was declared and defined in the subsequent line.
/usr/include/stdio.h:178:12: note: previous declaration of ‘remove’ was here?a = malloc(10); and thegetsfunction no longer exists.removefunction fails to null terminatestr2for(i=k;i<len;k++)Are you sure that you want to incrementk?