Shrikant Mahapatra Shrikant Mahapatra - 2 months ago 7
C Question

Passing and returning a string pointer in a function

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.

Answer

Function remove() is already defined in stdio.h.

int remove(const char *pathname);

Please give some other name to your function char* remove().

Note : Whenever you get such error, please try to look at manual page. If you are in unix. Simply type man func_name in terminal.

Comments