0

我在我的函数中收到这些编译警告,并且在我的代码中找不到任何错误:

警告:

src.c: In function ‘writeFiles’:
src.c:119:18: warning: character constant too long for its type [enabled by default]
src.c:119:2: warning: passing argument 1 of ‘fopen’ makes pointer from integer without a cast [enabled by default]
/usr/include/stdio.h:269:14: note: expected ‘const char * __restrict__’ but argument is of type ‘int’

我的功能:

FILE *outfile;
int writeFiles(int pwm, int rpm)
{

    outfile = fopen('/dev/fan/rpm', "w+");  /* line 119 with the warnings */ /*create the new file */ 
    fprintf(outfile, "%d", rpm);            /*write the rpm to the file */
    fclose(outfile);                        /*close the file */

    return ( 0 );

}

我希望你能帮助我解决这个问题。google 和 stackoverflow 都无法帮助找到解决此问题的方法。

4

3 回答 3

2

发生警告是因为fopen将 char* 作为参数,但您将其传递给(太长)char。

替换fopen('/dev/fan/rpm', "w+")fopen("/dev/fan/rpm", "w+")引号。

于 2013-05-03T19:30:29.990 回答
1

正如 Ryan 指出的那样,您的文件名实际上是一个char包含太多字符的文件。它解释了警告和注释。

于 2013-05-03T19:32:17.200 回答
0

我相信您需要在 fopen 调用中的文件名周围加上双引号。

例如

outfile = fopen("/dev/fan/rpm", "w+");
于 2013-05-03T19:30:50.493 回答