int fib[10];
。。。
char str[100] = {'\0'};
char stm[100] = {'\0'};
for(int s = 0;s <= num - 1;s ++)
{
sprintf(str,"%d",fib[s]);
strcat(stm,str);
strcat(stm," ");
}
memset(stm, 0, sizeof(stm));
memset(str, 0, sizeof(str));
字符串数组或者整数数组,转换为字符串输出。
int yfini_get_number(const char *ptitle,const char* psubname,const char *pinipath,int *pgetvalue)
{
int nresult=0;
char cbuf[255]={0},ctitlebuf[255]={0};
char *ppoint;
FILE *fp;
strcat(ctitlebuf,"[");
strcat(ctitlebuf,ptitle);
strcat(ctitlebuf,"]");
if((fp = fopen(pinipath,"r"))==NULL)
{
yflog_locallog_error("yfini_get_number %s error!",psubname);
return YF_LOG_ERROR;
}
while ((fgets(cbuf,sizeof(cbuf),fp))!=NULL)
{
if(cbuf[0]=='#')
continue;
if((strncmp(cbuf,ctitlebuf,strlen(ctitlebuf)))==0)
{
memset(cbuf,0,sizeof(cbuf));
while ((fgets(cbuf,sizeof(cbuf),fp))!=NULL)
{
if(cbuf[0]=='[')
{
nresult = YF_LOG_ERROR;
goto end;
}
if(cbuf[0]=='#')
{
continue;
}
if((strncmp(cbuf,psubname,strlen(psubname)))==0)
{
if((ppoint=strchr(cbuf,'='))!=NULL)
{
ppoint++;
*pgetvalue =atoi(ppoint);
nresult=YF_LOG_SUCCESS;
goto end;
}
else
{
nresult =YF_LOG_ERROR;
goto end;
}
}
}
nresult =YF_LOG_ERROR;
goto end;
}
nresult =YF_LOG_ERROR;
memset(cbuf,0,sizeof(cbuf));
}
end:
fclose(fp);
return nresult;
}
int yfini_get_string(const char *ptitle,const char* psubname,const char *pinipath,char *pgetvalue)
{
int nresult=0,nbuflen=0;
char cbuf[255]={0},ctitlebuf[255]={0};
char *ppoint;
FILE *fp;
strcat(ctitlebuf,"[");
strcat(ctitlebuf,ptitle);
strcat(ctitlebuf,"]");
if((fp = fopen(pinipath,"r"))==NULL)
{
yflog_locallog_error("yfini_get_string %s error!",psubname);
return YF_LOG_ERROR;
}
while ((fgets(cbuf,sizeof(cbuf),fp))!=NULL)
{
if(cbuf[0]=='#')
continue;
if((strncmp(cbuf,ctitlebuf,strlen(ctitlebuf)))==0)
{
memset(cbuf,0,sizeof(cbuf));
while ((fgets(cbuf,sizeof(cbuf),fp))!=NULL)
{
if(cbuf[0]=='[')
{
nresult = YF_LOG_ERROR;
goto end;
}
if(cbuf[0]=='#')
{
continue;
}
if((strncmp(cbuf,psubname,strlen(psubname)))==0)
{
if((ppoint=strchr(cbuf,'='))!=NULL)
{
ppoint++;
nbuflen=strlen(cbuf);
nbuflen-=ppoint -cbuf;
memcpy(pgetvalue,ppoint,nbuflen);
if(pgetvalue[nbuflen-1]=='\n')
{
pgetvalue[nbuflen-1]='\0';
}
if(pgetvalue[nbuflen-1]=='\r')
{
pgetvalue[nbuflen-1]='\0';
}
nresult =YF_LOG_SUCCESS;
goto end;
}
else
{
nresult =YF_LOG_ERROR;
goto end;
}
}
}
nresult =YF_LOG_ERROR;
goto end;
}
nresult =YF_LOG_ERROR;
memset(cbuf,0,sizeof(cbuf));
}
end:
fclose(fp);
return nresult;
}