Microchip
直播中

李锰

7年用户 181经验值
私信 关注
[问答]

未定义的标识符文件

大家好!我在初学C编程阶段。我想写一个代码,打开一个TXT文件,并写一些东西给它。我正在使用MPLAB X IDE(最新版本)和XC8编译器(最新版本)。当我写这些词:fOpen,fPrimtf,fHefft文件时,编译器说:未定义的标识符“文件”等等。我包括了STDIO .H标准库,在这些库中声明了这些命令,编译器不喜欢它。

以上来自于百度翻译


      以下为原文

    Hello guys!
Iam at a beginner stage in C programming. I would like to write a code which is open a txt file and write something to it. I'am using MPLAB X ide (latest) and an XC8 compiler ( latest ) . When i write these words : fopen , fprintf , fclose FILE , the compiler says   : undefined identifier "FILE" and such.
I included the stdio.h standard library where these commands are declared and the compiler doesn't like it anyway.

Here is my code:

回帖(9)

李广旭

2018-10-25 17:06:47
这里有一个我不能用它发布的代码:

以上来自于百度翻译


      以下为原文

    Here is a code  i can't post with it:
 

#include
#include

#define _HOSTED

void main (void) {
            
   FILE * fp;

   fp = fopen ("file.txt", "w+");
   fprintf(fp, "%s %s %s %d", "We", "are", "in", 2018);
   
   fclose(fp);
   
   return(0);
}
举报

李雨晨

2018-10-25 17:13:58
等等,请不要试图描述你的编译器输出的东西。请准确地指定您的版本。

以上来自于百度翻译


      以下为原文

   
 
and such ...
 
Please don't try to describe what your compiler outputs.
Post it literally by copy and paste
 

This does not mean anything. Please specify your version exactly.
举报

李广旭

2018-10-25 17:30:52
IAM使用XC8 1.45和MPLAB X IDE V4.15。错误是这样的。ILIPROSPA.xC8VC4\B\xC8exe“-PAS1= 18F97 J60-Q=G=24=24,EMI=WordDead -opt= +ASM,-ASMFLASH,+空间,-Debug,-Deal-AdrQualal=忽略-MODE=PRO-P-N255-警告=-3——ASMLIST- DXPRJIORADY = DEFALSE =摘要,默认,-PSECT,-+类,+MEM,-HEX,-file,输出=默认,运行时=默认,+,CONFIG,+CONFIG,+LIB,-PLIB -输出= -MCOF,+FLAS:堆栈=编译:Auto: Auto: Auto-“%r:%L:错误:(%N)%s:”警告:(%N)%s“”-MSGFLASE= %F:%L:咨询:(%N)%s“-OBUILD/Deult/NeaveNeMe.P.NeNeM.C:8:错误:(192)未定义的标识符“文件”NeMeun.C:8:错误:(192)未定义的标识符“FP”NeMeung.C: 10:警告:(361)函数声明隐式InNeNEng.C:11:警告:(361)函数声明隐式InNeNeM.C:13:警告:(361)乐趣C声明声明隐式InNeNo.Mc.:15:错误:(204)无效函数不能返回值(908)退出状态=1nbPosi/MaFaMeCurrase.MK:106:目标“Buff/Deule/Studio/NeMeNe.P1’FuleDebug [2 ]的配方:离开目录'C:/Huffe/MPLABXPixs/FielPuaF.x'NbPosi/MaFaCuff-DEFAOut.CONF'FultEdvest[[ 1 ] ]:留下目录'C://HETC/MPLABXPixs/FielPaul.x'NbPosi/MaFix.IMP.MK:39:Time'Buff.Buff-IMPL 'FuleDebug [2 ]的配方:**[Bug/Deule/Studio/NeMeun.P1]错误[1]:**[Buffic CONF]错误2:错误2Bug失败(退出值2,总时间:1s)

以上来自于百度翻译


      以下为原文

    Iam using XC8 1.45 and MPLAB X ide v4.15. The error is this.
 
 
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/Hitec/MPLABXProjects/fileproba.X'
make -f nbproject/Makefile-default.mk dist/default/production/fileproba.X.production.hex
make[2]: Entering directory 'C:/Users/Hitec/MPLABXProjects/fileproba.X'
"C:Program Files (x86)Microchipxc8v1.45binxc8.exe" --pass1 --chip=18F97J60 -Q -G --double=24 --float=24 --emi=wordwrite --opt=+asm,-asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=pro -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,-plib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/production/newmain.p1 newmain.c
newmain.c:8: error: (192) undefined identifier "FILE"
newmain.c:8: error: (192) undefined identifier "fp"
newmain.c:10: warning: (361) function declared implicit int
newmain.c:11: warning: (361) function declared implicit int
newmain.c:13: warning: (361) function declared implicit int
newmain.c:15: error: (204) void function can't return a value
(908) exit status = 1
nbproject/Makefile-default.mk:106: recipe for target 'build/default/production/newmain.p1' failed
make[2]: Leaving directory 'C:/Users/Hitec/MPLABXProjects/fileproba.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Hitec/MPLABXProjects/fileproba.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [build/default/production/newmain.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
 
举报

蒋喜玲

2018-10-25 17:38:47
这些功能在8位微控制器上是没有意义的。嵌入式代码不同于PC代码。例如,您的主程序不应该退出,因为没有操作系统退出。查看STDIO。h,这些函数原型和文件只定义为“托管”,在PIC16/18上基本上不存在。可能只有当你运行一个文件系统的RTOS时,所以不要使用文件、FOPEN等。

以上来自于百度翻译


      以下为原文

    These functions don't make sense on an 8bit microcontroller. Embedded code is different from PC code. Your main routine, for example, should never exit as there is no operating system to exit to.
 
Looking at stdio.h, these function prototypes, and FILE, are only defined if "_HOSTED" is defined, which on a PIC16/18 is basically never. Probably only if you run an RTOS with a file system.
 
So don't use FILE, fopen, etc.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分