- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 sprintf 将字符串消息的长度(整数)附加到另一个字符串。但每次我都会收到上述错误。
void ClientToServer(const char *client_msg)
{
char str_len[20];
int len = strlen(client_msg);
char *ptr;
sprintf(ptr,"AT+CIPSEND=0,%d",len);
}
完整错误:
CLEAN SUCCESSFUL (total time: 77ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/acer kuttan/Documents/pk/pk/TokenOverWiFi'
make -f nbproject/Makefile-default.mk dist/default/production/TokenOverWiFi.production.hex
make[2]: Entering directory 'C:/Users/acer kuttan/Documents/pk/pk/TokenOverWiFi'
"C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe" -mcpu=18F25K80 -c -fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/TokMain.p1 TokMain.c
"C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe" -mcpu=18F25K80 -c -fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/TokenTimer.p1 TokenTimer.c
"C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe" -mcpu=18F25K80 -c -fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/TokenWifi.p1 TokenWifi.c
"C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe" -mcpu=18F25K80 -c -fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/WifiCom.p1 WifiCom.c
WifiCom.c:24:1: warning: (361) function declared implicit int
"C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe" -mcpu=18F25K80 -Wl,-Map=dist/default/production/TokenOverWiFi.production.map -DXPRJ_default=default -Wl,--defsym=__MPLAB_BUILD=1 -fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -Wl,--memorysummary,dist/default/production/memoryfile.xml -o dist/default/production/TokenOverWiFi.production.elf build/default/production/TokMain.p1 build/default/production/TokenTimer.p1 build/default/production/TokenWifi.p1 build/default/production/WifiCom.p1
C:\Program Files (x86)\Microchip\xc8\v2.10\pic\sources\c90\common\sprintf.c:13:: error: (1098) conflicting declarations for variable "_sprintf" (WifiCom.c:24)
(908) exit status = 1
make[2]: *** [dist/default/production/TokenOverWiFi.production.hex] Error 1
nbproject/Makefile-default.mk:186: recipe for target 'dist/default/production/TokenOverWiFi.production.hex' failed
make[2]: Leaving directory 'C:/Users/acer kuttan/Documents/pk/pk/TokenOverWiFi'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/acer kuttan/Documents/pk/pk/TokenOverWiFi'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 7s)
编辑:警告
将 stdio.h 添加到所有头文件的顶部后,错误消失了,并出现了几个警告。
CLEAN SUCCESSFUL (total time: 49ms) make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf make[1]: Entering directory 'C:/Users/acer kuttan/Documents/pk/pk/TokenOverWiFi' make -f nbproject/Makefile-default.mk dist/default/production/TokenOverWiFi.production.hex make[2]: Entering directory 'C:/Users/acer kuttan/Documents/pk/pk/TokenOverWiFi' "C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe"
-mcpu=18F25K80 -c -fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/TokMain.p1 TokMain.c "C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe" -mcpu=18F25K80 -c
-fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/TokenTimer.p1 TokenTimer.c "C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe" -mcpu=18F25K80 -c
-fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/TokenWifi.p1 TokenWifi.c "C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe" -mcpu=18F25K80 -c
-fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/WifiCom.p1 WifiCom.c "C:\Program Files (x86)\Microchip\xc8\v2.10\bin\xc8-cc.exe" -mcpu=18F25K80
-Wl,-Map=dist/default/production/TokenOverWiFi.production.map -DXPRJ_default=default -Wl,--defsym=__MPLAB_BUILD=1 -fshort-double -fshort-float -memi=wordwrite -O1 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c90 -gdwarf-3 -mstack=compiled:auto:auto:auto -Wl,--memorysummary,dist/default/production/memoryfile.xml -o dist/default/production/TokenOverWiFi.production.elf build/default/production/TokMain.p1 build/default/production/TokenTimer.p1 build/default/production/TokenWifi.p1 build/default/production/WifiCom.p1 WifiCom.c:25:: warning: (1257) local variable "_ptr" is used but never given a value C:\Program Files (x86)\Microchip\xc8\v2.10\pic\sources\c90\common\doprnt.c:558:: warning: (1498) pointer (sprintf@sp) in expression may have no targets C:\Program Files (x86)\Microchip\xc8\v2.10\pic\sources\c90\common\doprnt.c:1465:: warning: (1498) pointer (sprintf@sp) in expression may have no targets C:\Program Files (x86)\Microchip\xc8\v2.10\pic\sources\c90\common\doprnt.c:1550:: warning: (1498) pointer (sprintf@sp) in expression may have no targets C:\Program Files (x86)\Microchip\xc8\v2.10\pic\sources\c90\common\doprnt.c:1564:: warning: (1498) pointer (sprintf@sp) in expression may have no targets ::: warning: (1311) missing configuration setting for config word 0x300003; using default
Memory Summary:
Program space used 89Ah ( 2202) of 8000h bytes ( 6.7%)
Data space used 229h ( 553) of E41h bytes ( 15.2%)
Configuration bits used 7h ( 7) of 7h words (100.0%)
EEPROM space used 0h ( 0) of 400h bytes ( 0.0%)
ID Location space used 8h ( 8) of 8h bytes (100.0%)
Data stack space used 0h ( 0) of B41h bytes ( 0.0%)
make[2]: Leaving directory 'C:/Users/acer kuttan/Documents/pk/pk/TokenOverWiFi' make[1]: Leaving directory 'C:/Users/acer kuttan/Documents/pk/pk/TokenOverWiFi'
BUILD SUCCESSFUL (total time: 9s) Loading code from C:/Users/acer kuttan/Documents/pk/pk/TokenOverWiFi/dist/default/production/TokenOverWiFi.production.hex... Loading completed
最佳答案
您正在将字符串打印到既未初始化也未在堆中分配内存的指针上。从日志的外观来看,您似乎正在将程序写入某种嵌入式系统,该系统可能没有通过虚拟内存进行任何内存保护,如果有,则可能会引发段错误。
将ptr
声明为任意大小的字符数组。鉴于您的格式字符串,我认为 30 就足够了,但是如果需要,您可以将其设置为更高
void ClientToServer(const char *client_msg)
{
int len = strlen(client_msg);
char ptr[30];
sprintf(ptr,"AT+CIPSEND=0,%d",len);
}
在您的代码中,ptr 可能拥有一些随机值,并且它将您的值写入系统上的某个地址,该地址甚至可能没有映射到您的指令/数据内存(尤其是 NULL)。我还删除了 str_len 数组,它似乎没有任何用途。
关于c - 错误: (1098) conflicting declarations for variable "_sprintf" in XC8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58500223/
在 JS 中从 Emscripten 编译的 WASM 创建 WebAssembly.Instance,其中包括对 sprintf 的调用,会导致此错误: Uncaught (in promise)
我想使用 sprintf 将字符串消息的长度(整数)附加到另一个字符串。但每次我都会收到上述错误。 void ClientToServer(const char *client_msg) {
对于一个研究项目,我正在为科学计算语言编写一个 C++ 插件。不幸的是,允许用户执行此操作的库没有保持最新状态。 我在 XCode 中启动了该项目,它构建得很好。后来我不得不搬到 PC,所以我将代码迁
对于一个研究项目,我正在为科学计算语言编写 C++ 插件。不幸的是,允许用户执行此操作的库并没有很好地保持最新状态。 我在 XCode 中启动了这个项目,在那里它构建得很好。后来我不得不搬到PC上,所
我链接到 ntdll.lib 以使用 ZwQueryInformationProcess 并使用多线程运行时库。 ntdll 似乎定义了一些crt 函数。因此,当我链接它并使用运行时库时,我会遇到链接
我是一名优秀的程序员,十分优秀!