Strange problem-an error occurs when the function returns more than three parameters.

Source: Internet
Author: User
Strange problem-an error occurs when the function returns more than three parameters-Linux general technology-Linux programming and kernel information. For details, refer to the following. In the following debugging program, as long as there are more than three GetCfg () function parameters, the output content in tst is garbled. I 'd like to ask.
System sco

# Include "stdio. h"
# Include
# Define PMAX_FUN 20
# Define INT int
# Define CHAR char
# Define INT int
# Define BOOL char
Main ()
{
INT nCnt;
CHAR * sProcCont [256];
CHAR sLine [] = "aaa | bbb | ccc ";

Memset (sProcCont, '\ 0', sizeof (sProcCont ));
// NCnt = GetFunCfg ("trmspfuncfg", "HOME", "trmsp/etc", "PROC", sProcCont );
// NCnt = GetCfg ("trmspfuncfg", "HOME", "trmsp/etc", "PROC", sProcCont );
NCnt = GetCfg1 ("aa", "HOME", "PROC", sProcCont );
// NCnt = Parse (sLine, sProcCont );

While (nCnt> = 0)
{
Printf ("xxxxx % d: % s \ n", nCnt, sProcCont [nCnt]);
NCnt --;
}
}

// INT GetCfg (CHAR * pFile, CHAR * pEnv, CHAR * pPath, CHAR * pFunNm, CHAR * pVal [])
INT GetCfg1 (CHAR * xx, CHAR * pEnv, CHAR * pFunNm, CHAR * pVal [])
{
INT nCnt = 0;
INT nLen = 0;
BOOL bFlag;
CHAR sPath [80];
CHAR sLine [PMAX_FUN * 10]; // each function can contain up to 10 Characters
FILE * fp;
// Char pFunNm [] = "PROC ";

Int I;

BFlag = 0;
NLen = strlen (pFunNm );
Memset (pVal, '\ 0', sizeof (pVal ));
Memset (sPath, 0x00, sizeof (sPath ));
// _ GetEnvPath (pEnv, pPath, sPath, sizeof (sPath ));
// Sprintf (sPath, "% s/% s", sPath, pFile );
Strcpy (sPath, "/usr/tstcom/trmsp/etc/trmspfuncfg ");

Printf ("88% s \ n", sPath );

If (fp = fopen (sPath, "r") = NULL)
{
Printf ("open trmspcont err! \ N ");
Exit (1 );
}


While (fgets (sLine, sizeof (sLine), fp )! = NULL)
{
If (sLine [0] = '#')
Continue;
If (isspace (sLine [0])
Continue;

If (bFlag = 1) & (sLine [0] = '['))
{
Break;
}
If (bFlag = 1) & (sLine [0]! = '['))
{
Printf ("999% s \ n", sLine );
NCnt = Parse (sLine, pVal );
For (I = nCnt-1; I> = 0; I --)
Printf ("yyy % s \ n", pVal );
Break;
}

If (sLine [0] = '[')&&! Memcmp (& sLine [1], pFunNm, nLen )&&
(SLine [nLen + 1] = ']') // ensure full match
{
BFlag = 1;
Continue;
}
}

Fclose (fp );
Return (nCnt );
}


-------------------------------------

The Parse function is as follows:

INT Parse (CHAR * pLine, CHAR * pWord [])
// INT Parse (CHAR * pLine, CHAR pWord [] [20])
{
INT nWordCnt;
Int I;

NWordCnt = 0;
While (* pLine! = 0x00) & (* pLine! = '\ N '))
{
While (* pLine = '') | (* pLine = '\ t') |
(* PLine = '| '))
* PLine ++ = 0x00;
PWord [nWordCnt ++] = pLine;
// Strcpy (pWord [nWordCnt ++], pLine );

While (* pLine! = 0x00) & (* pLine! = '')&&
(* PLine! = '\ T') & (* pLine! = '\ N ')&&
(* PLine! = '| '))
PLine ++;
}
* PLine = 0x00;

Return (nWordCnt );
}


--------------
The contents of the trmsfuncfg file are as follows:
#
#
[MAIN]
Proc
[PROC]
Comcli | comsrv | trmspproc

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.