数组转字符串

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;

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值