c - 在函数中传递和返回字符串指针

标签 c

我对字符指针和字符串的概念不熟悉。因此,在函数中传递字符串指针和返回字符串指针时遇到问题。函数是“删除”。

#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/

相关文章:

c - 获取 SCSI 的供应商名称

c - 在 Xcode 中构建旧的 unix C 项目时指针给出错误?

检查线程结束条件

c - 为什么 sizeof (void(*)(void)) 打印 8?

c - WinSDK 7.1 : Getting Started with the Windows SDK Tools for Native Windows app development?

调用必须有指针 - CCS 问题

c - 结构数组的空闲内存

c - 我正在创建一个程序,它接受用户的五个输入并使用另一个函数显示最大的输入

c - 套接字 - 发现防火墙端口

python - C 中的 For 循环没有明显原因提前中断 - 可能与函数指针(回调)有关