注释c语言程序哦~大神来帮助下 ,注释好了追加100分,急要!!!

程序有点长就注释下这部分吧~intGetCFGValue(char*CFGBuffer,intBuflen,char*pKeyName,char*pItemName,ch... 程序有点长 就注释下这部分吧~
int GetCFGValue( char* CFGBuffer, int Buflen, char *pKeyName, char *pItemName, char* pStr )
{
int i1, i2, len1, len2;

len1 = strlen( pKeyName );
len2 = strlen( pItemName );

for( i1=0; i1<Buflen; i1++ )
{
if( strncmp( &CFGBuffer[i1], pKeyName, len1 ) == 0 )
{
i1 += len1;
break;
}
}
上面这部分不完整,只截了一段,然后是接下面的
int GetConfigValue( char* FileName, CONFIG_INFO* pConfigInfo )
{
FILE* fp;
char ValueStr[80];
char Buffer[1000], str[100];
int nBytes;
int i;

fp = fopen( FileName, "rt" );
if( fp!=NULL )
{
fread( Buffer, 1000, 1, fp );
nBytes = strlen( Buffer );
fclose( fp );
if( nBytes > 0 )
{
//get ip address
if (0 == GetCFGValue( Buffer, nBytes, "[IPADDR]", "ip=", ValueStr )) {
sprintf(pConfigInfo->ipaddr, "ifconfig eth0 %s", ValueStr);
} else {
strcpy( pConfigInfo->ipaddr , "ifconfig eth0 192.168.0.222");
}
// get tcpserver parameters: base port
if (0 == GetCFGValue( Buffer, nBytes, "[TCPServer]", "BasePort=", ValueStr ))
{
pConfigInfo->TCPBasePort = atoi( ValueStr );
}

// get serial parameters
for( i=0; i<6; i++ )
{
sprintf( str, "ttys%d=", i+1 );
if (0 == GetCFGValue( Buffer, nBytes, "[RS232]", str, ValueStr ) )
{
sscanf( ValueStr, ("%d-%d-%d-%c"), &pConfigInfo->BaudRate[i], &pConfigInfo->DataBits[i],
&pConfigInfo->StopBits[i], &pConfigInfo->Parity[i] );
}
printf("BaudRate[%d] = %d\n", i, pConfigInfo->BaudRate[i]);
printf("DataBits[%d] = %d\n", i, pConfigInfo->DataBits[i]);
printf("Parity[%d] = %c\n", i, pConfigInfo->Parity[i]);
printf("StopBits[%d] = %d\n", i, pConfigInfo->StopBits[i]);
}
}
}
return 0;
}

/*判断参数是否正确*/
int iscorrectcfg(CONFIG_INFO* pConfigInfo)
{
int i;

if (pConfigInfo->TCPBasePort < 1000 || pConfigInfo->TCPBasePort > 20000)
pConfigInfo->TCPBasePort = 1234;

for (i = 0; i < 6; i++) {
if (pConfigInfo->BaudRate[i] < 300 || pConfigInfo->BaudRate[i] > 230400)
pConfigInfo->BaudRate[i] = 9600;
if (pConfigInfo->DataBits[i] < 5 || pConfigInfo->DataBits[i] > 8)
pConfigInfo->DataBits[i] = 8;
if (pConfigInfo->Parity[i] != 'N' ||pConfigInfo->Parity[i] != 'n' ||\
pConfigInfo->Parity[i] != 'O' ||pConfigInfo->Parity[i] != 'o' ||\
pConfigInfo->Parity[i] != 'E' ||pConfigInfo->Parity[i] != 'e' ||\
pConfigInfo->Parity[i] != 'S' ||pConfigInfo->Parity[i] != 's' ) {
pConfigInfo->Parity[i] = 'n';

}
if (pConfigInfo->StopBits[i] != 0 || pConfigInfo->StopBits[i] != 1 || pConfigInfo->StopBits[i] != 2)
pConfigInfo->StopBits[i] = 1;
printf("BaudRate[%d] = %d\n", i, pConfigInfo->BaudRate[i]);
printf("DataBits[%d] = %d\n", i, pConfigInfo->DataBits[i]);
printf("Parity[%d] = %c\n", i, pConfigInfo->Parity[i]);
printf("StopBits[%d] = %d\n", i, pConfigInfo->StopBits[i]);
}

return 0;
}
展开
 我来答
爬小蜗
2012-06-22
知道答主
回答量:18
采纳率:100%
帮助的人:10.8万
展开全部
int GetCFGValue( char* CFGBuffer, int Buflen, char *pKeyName, char *pItemName, char* pStr ) //函数入口
{
int i1, i2, len1, len2; //变量声明

len1 = strlen( pKeyName ); //得到pKeyName长度,不包括‘\0’。如果pKeyName没有初始化,结果将不确定
len2 = strlen( pItemName ); //同pKeyName解释

for( i1=0; i1<Buflen; i1++ ) //循环,直到i1大于等于 Buflen
{
if( strncmp( &CFGBuffer[i1], pKeyName, len1 ) == 0 ) //检查pKeyName与CFGBuffer[i1]是否相同
{
i1 += len1; //如果相同i1增加len1长度,使CFGBuffer[i1]是与pKeyName相同的后一位
break; //结束循环
}
}
上面这部分不完整,只截了一段,然后是接下面的
int GetConfigValue( char* FileName, CONFIG_INFO* pConfigInfo ) //函数入口
{
FILE* fp; //声明文件指针
char ValueStr[80]; //声明字符串数组
char Buffer[1000], str[100]; //声明字符串数组
int nBytes; //声明变量
int i; //声明变量

fp = fopen( FileName, "rt" ); //只读打开FileName,只允许读数据
if( fp!=NULL ) //如果文件被打开
{
fread( Buffer, 1000, 1, fp ); //读入数据,存放位置,单个元素大小,读入数量,数据位置 ????
nBytes = strlen( Buffer ); //得到Buffer长度
fclose( fp ); //关闭文件
if( nBytes > 0 ) //如果Buffer存在内容
{
//get ip address
if (0 == GetCFGValue( Buffer, nBytes, "[IPADDR]", "ip=", ValueStr )) { //调用GetCFGValue函数,GetCFGValue这个函数不全,我也不知道是做什么的
sprintf(pConfigInfo->ipaddr, "ifconfig eth0 %s", ValueStr); //输出
} else {
strcpy( pConfigInfo->ipaddr , "ifconfig eth0 192.168.0.222"); //数据复制给pConfigInfo->ipaddr
}
// get tcpserver parameters: base port
if (0 == GetCFGValue( Buffer, nBytes, "[TCPServer]", "BasePort=", ValueStr ))//调用GetCFGValue函数
{
pConfigInfo->TCPBasePort = atoi( ValueStr ); //赋值
}

// get serial parameters
for( i=0; i<6; i++ ) //循环
{
sprintf( str, "ttys%d=", i+1 ); //终端输出
if (0 == GetCFGValue( Buffer, nBytes, "[RS232]", str, ValueStr ) )//调用GetCFGValue函数
{
sscanf( ValueStr, ("%d-%d-%d-%c"), &pConfigInfo->BaudRate[i], &pConfigInfo->DataBits[i],
&pConfigInfo->StopBits[i], &pConfigInfo->Parity[i] ); //把ValueStr以("%d-%d-%d-%c")此格式依次写入后面的参数
}
printf("BaudRate[%d] = %d\n", i, pConfigInfo->BaudRate[i]); //终端输出
printf("DataBits[%d] = %d\n", i, pConfigInfo->DataBits[i]);//终端输出
printf("Parity[%d] = %c\n", i, pConfigInfo->Parity[i]);//终端输出
printf("StopBits[%d] = %d\n", i, pConfigInfo->StopBits[i]);//终端输出
}
}
}
return 0; //然会0
}

/*判断参数是否正确*/
int iscorrectcfg(CONFIG_INFO* pConfigInfo) //函数入口
{
int i; //变量声明

//以下都是一些对比,不解释了

if (pConfigInfo->TCPBasePort < 1000 || pConfigInfo->TCPBasePort > 20000)
pConfigInfo->TCPBasePort = 1234;

for (i = 0; i < 6; i++) {
if (pConfigInfo->BaudRate[i] < 300 || pConfigInfo->BaudRate[i] > 230400)
pConfigInfo->BaudRate[i] = 9600;
if (pConfigInfo->DataBits[i] < 5 || pConfigInfo->DataBits[i] > 8)
pConfigInfo->DataBits[i] = 8;
if (pConfigInfo->Parity[i] != 'N' ||pConfigInfo->Parity[i] != 'n' ||\
pConfigInfo->Parity[i] != 'O' ||pConfigInfo->Parity[i] != 'o' ||\
pConfigInfo->Parity[i] != 'E' ||pConfigInfo->Parity[i] != 'e' ||\
pConfigInfo->Parity[i] != 'S' ||pConfigInfo->Parity[i] != 's' ) {
pConfigInfo->Parity[i] = 'n';

}
if (pConfigInfo->StopBits[i] != 0 || pConfigInfo->StopBits[i] != 1 || pConfigInfo->StopBits[i] != 2)
pConfigInfo->StopBits[i] = 1;
printf("BaudRate[%d] = %d\n", i, pConfigInfo->BaudRate[i]);
printf("DataBits[%d] = %d\n", i, pConfigInfo->DataBits[i]);
printf("Parity[%d] = %c\n", i, pConfigInfo->Parity[i]);
printf("StopBits[%d] = %d\n", i, pConfigInfo->StopBits[i]);
}

return 0;
}

有不对的地方还请大虾改正

那么晚提问题,楼主很好学啊

参考资料:

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式