我得到這些編譯警告,在我的功能並不能找到我的代碼的任何錯誤:編寫文件時編譯警告,最新錯誤?
警告:
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都不能幫助找到解決這個問題的辦法。
你能在你的代碼片段中標出給出警告的行號嗎?另外'fopen'需要一個char *作爲第一個參數,爲什麼你的分隔符是單引號? – Ryan 2013-05-03 19:28:04
'''字符是你的問題。僅爲單個字符使用單引號。對於字符串使用雙引號。 – 2013-05-03 19:30:23
''/ dev/fan/rpm'' --->'「/ dev/fan/rpm」' – BLUEPIXY 2013-05-03 19:31:10