当前位置:网站首页>【C编译】报错问题收集
【C编译】报错问题收集
2022-08-06 14:57:00 【一苇以航fp】
1、[Note] each undeclared identifier is reported only once for each function it appears in
[注] 每个未申报的标识符是为每一个函数似乎只报道一次(写错了或多写了标识符)
如:
printf("f("%s", "%s") = %d\n", p, q, result);
修改:
printf("f(\"%s\", \"%s\") = %d\n", p, q, result);
printf 函数里面 双引号需要 \ 才能无误地原样输出。
2、[Warning] initialization discards ‘const’ qualifier from pointer target type
[警告] 初始化时丢弃了从指针目标类型中丢弃了
const限定符
如:
const int a[10] = {
0};
char* p = a; //会出现此Warning
解决办法:
const int a[10] = {
0};
const int* p = a;
3、[Error] variable-sized object may not be initialized
[错误] 可变长度的对象没有被初始化
如:
int n = 5;
int a[n] = {
1,2,3,4,5};
错因:
对于可变长度数组(长度由变量控制), 不能在该数组定义的同时初始化,需要在定义之后单独赋值初始化。
修改:
int n = 5;
int a[n];
memset(a, 0, sizeof(a)); //合法初始化,将a的所有元素初始化为0
4、[Error] ld returned 1 exit status
[错误] ld返回一个退出状态
可能原因:
- 上一个运行结果没有关闭
5、[Error] stray ‘\241’ in program
可能原因:程序中有非法字符,可能不小心转换成全角输入了。
6、调试结果与运行结果不一致
如:
#include <stdio.h>
#include <string.h>
#define LEN 500 //限制输入的字符串长度
int main(){
char str[LEN+1], differ[LEN+1]; //此处数组未初始化
int len_str, len_differ;
int i;
scanf("%s", str);
len_str = strlen(str);
strncpy(differ, str, 1);
len_differ = strlen(differ);
//在differ中逐个检索str中的元素
for(i=0; i<len_str; i++){
//没被记录
if( strchr(differ, str[i]) == NULL ){
//单个字符拼接到differ末尾
differ[strlen(differ)] = str[i];
differ[strlen(differ) + 1] = '\0';
}
}
printf("%d", strlen(differ));
return 0;
}
错误原因:暂且未知
解决办法:把数组初始化
7、调试时无法输入
问题描述:
点击调试后弹出对话框,但对话框立即最小化,且无法输入。
原因:
断点设置在 scanf 那一行。
解决办法:
修改断点,将断点设置在输入函数后面。
8、[Error] assignment to expression with array type
错误原因:
- 数组不能直接给数组赋值。
解决办法:
- 若是字符串,可使用
strcpy函数 - 若是数组,则需要逐个赋值。
边栏推荐
- CSDN 21-day Learning Challenge - The first punching article
- [2022CISCN]初赛 复现
- From technical panorama to scene combat, analyze the evolutionary breakthrough of "narrowband HD"
- 00后写个暑假作业,被监控成这笔样
- DAO:Web3 的必要组件
- 【Paper Speed Reading】NLNL: Negative Learning for Noisy Labels (ICCV2019)
- Field userService in com.zher.reggie_task_out.controller.UserController required a bean of type ‘com
- The basic process used by mosquitto and some problems encountered
- ES核心概念
- 我终于逃离了互联网,却陷入了迷茫
猜你喜欢
随机推荐
互斥锁 try_lock 自旋锁 读写锁 原子操作 共享内存
MODBUS to PROFINET gateway to connect power intelligent monitoring instrument to PROFINET network case
深入浅出边缘云 | 5. 运行时控制
LeetCode_Recursive_Medium_397. Integer Substitution
MySQL数据库成为瓶颈后,动态数据的查询要如何加速?
How much does Ark Survival Evolved self-built server cost?
Why do LiveVideoStack courses?
[Installation filling pit] -import win32api, sys, os ImportError: DLL load failed: The specified module could not be found.
Tencent Cloud Hu Qiming: Analysis and Optimization of Kubernetes Cloud Resources
Zhaoqi Science and Technology Innovation and Entrepreneurship Service Platform, introduction of high-level talents for innovation and entrepreneurship, investment and financing docking
LeetCode_递归_中等_397.整数替换
听声辨物,这是AI视觉该干的???|ECCV 2022
腾讯欲成育碧最大股东/ 米哈游招NLP内容生成研究员/ AI发现四千余物种濒临灭绝...今日更多新鲜事在此...
Two Set collections get the same elements
传奇开服教程:传奇无限制仓库脚本分享
Field userService in com.zher.reggie_task_out.controller.UserController required a bean of type ‘com
00后写个暑假作业,被监控成这笔样
为什么国债逆回购很安全?
nodejs(四)自定义模块加载机制,第三方模块的加载机制,目录作为模块
Machine learning notes (Wu En up to the teacher)









