使用C程序csv文件转换为特定的格式有关 [英] regarding using a c program for converting csv file to a specific format

查看:184
本文介绍了使用C程序csv文件转换为特定的格式有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用convert.c,其设置在LIBSVM网站,CSV文件转换为LIBSVM数据格式。但我从来没有使用C和该网站没有提供有关如何使用该程序的任何信息。我可以从这里得到任何提示?以下是code。非常感谢。

 的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#包括LT&;&string.h中GT;焦炭BUF [千万]
浮动特征[100000]。INT主(INT ARGC,字符** argv的)
 {
FILE * FP;如果(ARGC = 2!){fprintf中(标准错误,用法%S文件名\\ n,argv的[0]); }
如果((FP = FOPEN(的argv [1],R))== NULL)
{
    fprintf中(标准错误,无法打开输入文件%s \\ n,ARGV [1]);
}
而(的fscanf(FP,%[^ \\ n] \\ n,BUF)== 1)
{
    INT I = 0,J;
    的char * p = strtok的(BUF,);    特征[I ++] = ATOF(对);    而((p值= strtok的(NULL,,)))
        特征[I ++] = ATOF(对);    // - 一世;
    / *
    如果((int)的特性[Ⅰ] == 1)
        的printf( - 1);
    其他
        输出(+ 1);
    * /
    //的printf(%F功能[1]);
    的printf(%D,(int)的特征[0]);
    为(J = 1; J< I; J ++)
        的printf(%d个:%F,J,特征[J]);
    的printf(\\ n);
}
返回0;
  }


解决方案

您可以找到有关如何在这里使用它的信息:

 如果(ARGC = 2!){fprintf中(标准错误,用法%S文件名\\ n,argv的[0]); }
如果((FP = FOPEN(的argv [1],R))== NULL)
{
   fprintf中(标准错误,无法打开输入文件%s \\ n,ARGV [1]);
}

所以,你需要提供两个参数,一个是程序名,这是的argv [0] 的argv [1] 是输入文件名。

我猜你应该做的:(第一,编译code到一个EXE文件)
然后在命令行,走的exe文件目录,键入:

  PROGRAMNAME文件名

为了用自己的code。而 PROGRAMNAME 是转换程序的名称。

我的猜测是,code将读取你的csv文件,并提取可用于SVM分类数据集的所有功能。

I am trying to use the convert.c, which is provided on libsvm website, to convert the csv file to libsvm data format. But I never use C and the website does not provide any information on how to use this program. Can I get any hint from here? The following is the code. Many thanks.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char buf[10000000];
float feature[100000];

int main(int argc, char **argv)
 {
FILE *fp;

if(argc!=2) { fprintf(stderr,"Usage %s filename\n",argv[0]); }
if((fp=fopen(argv[1],"r"))==NULL)
{
    fprintf(stderr,"Can't open input file %s\n",argv[1]);
}
while(fscanf(fp,"%[^\n]\n",buf)==1)
{
    int i=0,j;
    char *p=strtok(buf,",");

    feature[i++]=atof(p);

    while((p=strtok(NULL,",")))
        feature[i++]=atof(p);

    //      --i;
    /*
    if ((int) feature[i]==1)
        printf("-1 ");
    else
        printf("+1 ");
    */
    //      printf("%f ", feature[1]);
    printf("%d ", (int) feature[0]);
    for(j=1;j<i;j++)
        printf(" %d:%f",j,feature[j]);
    printf("\n");
}
return 0;
  }

解决方案

You can find information about how to use it here:

if(argc!=2) { fprintf(stderr,"Usage %s filename\n",argv[0]); }
if((fp=fopen(argv[1],"r"))==NULL)
{
   fprintf(stderr,"Can't open input file %s\n",argv[1]);
}

So you need to provide 2 arguments, and one is program name, which is argv[0], argv[1] is your input file name.

I guess you should do: (firstly, compile the code into an exe file) then from command line, go the exe file directory, type:

programname filename

in order to use their code. While programname is the conversion program name.

My guess is that the code will read your csv file and extract all features of a data set that can be used for SVM classification.

这篇关于使用C程序csv文件转换为特定的格式有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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