c - 编译代码时出现 atof 冲突

标签 c mingw atof

我刚刚开始我的 C 编程之旅。我遇到了库冲突的问题。请在下面找到我的示例代码。

#include <stdio.h>
#include <stdlib.h>
#define MAXLINE 100


//int getline declaration is here (removed for simplicity)

int main()
{
    double sum, atof(char []);
    char line[MAXLINE];
    int getline(char line[], int max);

    sum=0;
    while (getline(line,MAXLINE)>0)
        printf("\t%g\n", sum += atof(line));
40mi    return 0;
}

当我运行此代码时,出现以下编译错误:

Error: conflicting types for 'atof'

我正在使用 CodeBlocks + mingw c 编译器

编辑(回应评论):

我想下载一个参数,并且可能返回一个 double 值,atof 无需 stdlib.h 即可工作,但无法定义 获取线

最佳答案

如果包含 stdlib,则无需声明 atof。它在 stdlib 中声明。 stdlib 中 atof 的定义为 double atof(const char *nptr)。它与你的不同,这解释了冲突。

getline 在 stdio.h 中定义,需要三个参数:ssize_t getline(char **lineptr, size_t *n, FILE *stream)。您无法像您那样使用 getline 从标准输入读取。你必须使用 getline(line, MAXLINE, stdin) 。并且不要在 main 中声明它,因为它已经在 stdio.h 中声明了。

关于c - 编译代码时出现 atof 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28895389/

相关文章:

c - C 中的动态编程资源?

c - 如何在 C 中实现我自己的基本 unix shell?

performance - 提高 Ruby on Rails 性能 Windows 7

c++ - 用 C/C++ 编译 DLL,然后从另一个程序调用它

c - 如何将命令行参数读入 C 中的双数组/vector ?

c - printf如何改变函数的返回值?

c++ - 在 Windows 7 上开始使用 OpenCV 2.4 和 MinGW

c - 如何在可移植 C 中将很长的字符串转换为 double

c++ - 带有gcc 7.4.0的奇怪std::atof错误

c - 管道、Fifo、read() 和 write() 函数