我对字符指针和字符串的概念不熟悉。因此,在函数中传递字符串指针和返回字符串指针时遇到问题。函数是“删除”。
#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;
}
我得到的错误是
error:conflicting types for 'remove'
在声明和定义函数的行中,在后续行中。
最佳答案
函数 remove()
已经在 stdio.h
中定义。
int remove(const char *pathname);
请为您的函数 char* remove()
指定其他名称。
注意:每当您遇到此类错误时,请尝试查看手册页。如果你在 unix 中。只需在终端中输入 man func_name
。
关于c - 在函数中传递和返回字符串指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39341241/