如何从CSV文件读取NUll值 [英] How to read NUll value from CSV File

查看:1191
本文介绍了如何从CSV文件读取NUll值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,
我有一个Senario,我想从CSV文件(C,C ++)中读取数据,并且需要存储

以下是示例

444444,TESCO,3WHEEL,SONY,HIGH(这是一个csv文件的记录)
我正在使用下面的代码存储所有值,而不是安倍存储",,"

Dear Friends,
i have a senario where i am suppose to read the data from the CSV file(C,C++),and need to store

below is example

444444,TESCO,3WHEEL,SONY,,HIGH ( this is one record of a csv file)
i am using below code to store all the value, but not abe to store ",,"

void GetColumnValue( const char *lc_Record, char *Delim, char *pColmnName, long *FldCnt )
 {

     char Record[256] = {'\0'};
     char ItemCd[16]  = {'\0'};
     char AttrVal[21] = {'\0'};<code></code>
     char CompStr[1000] = {'\0'};

     long ll_FldCnt = 0;
     long ll_AttrNo = 0;


     strcpy(Record,lc_Record);
     char* p = strtok( Record, Delim );
     while( p != NULL )
     {
        if(ll_FldCnt == 0)
        {
            strcpy(ItemCd,p);
            strcat(ItemCd,",");
            //fprintf(pRes,"%s",ItemCd);
        }
        else
        {
            if( strlen(p) == 0 )
            {
                sprintf(gc_log, "There is no AttrValue in Request File For Itemcode %s and attrno %s",ItemCd, pConfigFile[ll_FldCnt].AttrNo );
                LogInfo(gc_log);
                continue;
            }
            strcpy(AttrVal,p);

            TrimString( AttrVal, '\n',2 );

 strcpy( CompStr, ItemCd );
            strcat( CompStr, pConfigFile[ll_FldCnt].AttrNo );
            strcat( CompStr,"," );
            strcat( CompStr, AttrVal );
            strcat( CompStr,"," );
            strcat( CompStr, gc_sysDt );
            strcat( CompStr,"," );
            strcat( CompStr, g_user_name );
            strcat( CompStr,"," );
            strcat( CompStr, gc_sysDt );
            strcat( CompStr,"," );
            strcat( CompStr, g_user_name );        }
        p=strtok( NULL,Delim);
        if( ll_FldCnt != 0 )
            fprintf( gp_RespFile,"%s\n",CompStr);
        ll_FldCnt++;
        strcpy( CompStr, "");

     }
     //fclose( gp_RespFile );
 }


请让我知道如何解决它

亲切的问候,
praveer

以正确的方式添加标签-johny [/Edit]


please let me know how to fix it

Kind regards,
praveer

Adding Tag in proper way- johny[/Edit]

推荐答案

您可以检查字符串中是否存在两个连续的逗号(,),然后您可以确定是吗?
you could check if two consecutive commas(,) are present in string , then you can decide it right ?


如果条目中没有数据,您的代码将显示一条消息.这段代码行不通吗?如果它可以正常工作,那到底是什么问题?你写这段代码了吗?你懂吗?
Your code shows a message if there''s no data in an entry. Is this code not working ? If it is working, what exactly is your issue ? Did you write this code ? Do you understand it ?


这篇关于如何从CSV文件读取NUll值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆