完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好!我在初学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个回答
|
|
这里有一个我不能用它发布的代码:
以上来自于百度翻译 以下为原文 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); } |
|
|
|
等等,请不要试图描述你的编译器输出的东西。请准确地指定您的版本。
以上来自于百度翻译 以下为原文 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. |
|
|
|
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) |
|
|
|
这些功能在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. |
|
|
|
您不能使用任何基于文件的命令,因为您的PIC不包含文件操作系统。您希望文件保存在什么地方?
以上来自于百度翻译 以下为原文 You can't use any of those file based commands, because your PIC does not contain a file operating system. Where exactly do you expect the files to be saved? |
|
|
|
在演示代码中,有一个TXT文件,我认为我也可以这样做,向项目中添加一个现有的TXT文件并写入它。
以上来自于百度翻译 以下为原文 In a demo code , there is a txt file and i thought i can do the same , add an existing txt file to the project and write to it. |
|
|
|
“它”在芯片上没有硬盘驱动器。它需要在RAM或闪光灯中。这可能在小型8位芯片上,但不常见。
以上来自于百度翻译 以下为原文 “It” there is no hard drive on the chip. It would need to be in the RAM or the flash. This is possible on small 8 bit chips, but not common. |
|
|
|
这里有一个网站,所以也许我把文本保存到RAM并打印到网站上。也许就是这样。或者如果我写一个TXT文件可能是RS232?问题是我想记录和计算谁以及何时登录到Web。
以上来自于百度翻译 以下为原文 There is a web for this , so maybe i save texts to the RAM and print it to the website. Maybe that is the way. Or if i write to a txt file trought RS232 maybe? The thing is i want to log and count who and when logged into the web. |
|
|
|
正如这里已经说过的,不能简单地写入文件。但是,即使你可以,这似乎没有帮助你的应用程序。你指的是哪一个示例代码,“这有一个Web”是什么意思?它与微芯片嵌入式设备有什么关系吗?XC8 1.45编译器手册说:Prtff()函数是一个格式化的输出例程,在STDUT上运行。它依赖于PUCHH()函数来确定标准输出流的目的地。此外,还提供了用于PTCH(DS5000 02053H页401)的文件,作为一个空存根,可以按项目要求完成。如果您打算使用Primff()函数,则必须定义它。通常,这个函数将接受一个字节的数据,并将其发送到与STDUT相关联的外围设备。您可以使用fdtff与STDUT(或类似)作为参数,这将与PrtTf相同,但由于这将没有任何好处,现在只需查看PrtTf。(我也不知道微芯片的实现)。这允许你通过UART重新路由你的输出,或者做你想要的任何输出。你也会发现论坛中的线程处理重路由PROTF。但是接下来的问题是,为什么你要使用PrTNFA FA?mily?所以我仍然怀疑这是你真正需要的,你必须解释一下你想做什么。
以上来自于百度翻译 以下为原文 As already told here, you cannot simply write to a file. But even if you could, this seems not to help you with your application. Which example code are you referring to and what does "there is a web for this" mean ? Does it have anything to do with Microchip embedded devices ? Your XC8 1.45 compiler manual says: The printf() function is a formatted output routine, operating on stdout. It relies on the putch() function to determine the destination of the standard output stream. And also the documentation for putch (DS50002053H-page 401) The putch() function is provided as an empty stub which can be completed as each project requires. It must be defined if you intend to use the printf() function. Typically this function will accept one byte of data and send this to a peripheral which is associated with stdout. You might use fprintf with stdout (or similar) as parameter, which then would be the same as printf, but since this would not have any benefit, just look at printf for now. (also I have no idea bout Microchips implementation). This allows you to reroute your output through e.g. UART, or do whatever you want with that output. You also will find threads in the forum dealing with rerouting printf. But then the next question would be, WHY do you you want to use the printf family ? So I still doubt that this is what you really need, you would have to explain a bit what you want to do |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2027 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3202 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
772浏览 1评论
663浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
590浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
672浏览 0评论
572浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 11:50 , Processed in 1.410514 second(s), Total 92, Slave 76 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号