C语言中变量定义的位置
作者:网络转载 发布时间:[ 2012/10/18 10:25:27 ] 推荐标签:
C++中,变量定义可以在函数中的任意位置,比如函数中任意位置出现的For循环中:
for(int i = 0; i< len; i++) {
/*do something;*/
}
变量i可以在使用到的地方才给定义;
然而在C语言中,变量的定义一定要在函数体的开始处;
否则在使用到变量的地方才定义,编译的时候会报不认识此变量,如下这个屏幕字段入口函数:
Fi_120015_01_CICUSENA()
{
char acRegFlg[2];
GetStr("K_C00101",acRegFlg);
Trim(acRegFlg);
/*非记名卡跳过 */
if(acRegFlg[0]=='0')
{
return SKIP;
}
/*判断输入的姓名是否为拼音*/
char Name[71];
int len = 0;
GetStr("CICUSENA",Name);
/*取数组长度*/
/* len = (sizeof(Name)/sizeof(Name[0])); */
len = strlen(Name);
for(int i = 0; i < len; i++)
{
if(!((Name[i]>'A' && Name[i]<'Z') || (Name[i]>'a' && Name[i]<'z')))
{
v_warning(0,"请输入姓名对应的拼音");
return INVALID;
}
}
return 0;
}
编译,然后出现下面的错误:
[开发]/usr/AAAAA/src/cds/120015>msoe
->编译 120015.fe ...... 120015.c:
"120015.ec", line 248: error: Syntax error before or at: int
"120015.ec", line 250: error: undefined symbol: Name
"120015.ec", line 253: error: undefined symbol: len
"120015.ec", line 253: error: cannot dereference non-pointer type
"120015.ec", line 254: error: Syntax error before or at: int
"120015.ec", line 254: error: undefined symbol: i
"120015.ec", line 254: error: Syntax error before or at: )
"120015.ec", line 260: error: Syntax error before or at: return
"120015.ec", line 260: warning: syntax violation: empty declaration
120015.c:
"120015.ec", line 248: error: Syntax error before or at: int
"120015.ec", line 250: error: undefined symbol: Name
"120015.ec", line 253: error: undefined symbol: len
"120015.ec", line 253: error: cannot dereference non-pointer type
"120015.ec", line 254: error: Syntax error before or at: int
"120015.ec", line 254: error: undefined symbol: i
"120015.ec", line 254: error: Syntax error before or at: )
"120015.ec", line 260: error: Syntax error before or at: return
"120015.ec", line 260: warning: syntax violation: empty declaration
*** Error code 2 (bu21)
mv: cannot access 120015.so: No such file or directory (error 2)
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11