#include int main(int argc, char *argv[]) { //Decralation of variables int i; int r,g,b; unsigned long newline_count=0; FILE *fpi,*fpo; float x,y,z; if(argc!=3) { fprintf(stderr,"Usage: %s (1)CSVFile\n(2)VTKFile\n",argv[0]); return 0; } //Open VTK file for save if((fpo=fopen(argv[2],"w"))==NULL) { printf("The file can't be opened. The program is exit.\n"); return 0; } //count how many lines /* while((c==fgetc(fpi))!=EOF { if(c=='\n') newline_count++; } */ while (fscanf(fpi,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!=EOF) { newline_count=newline_count+1; } printf("total=%ld\n",newline_count); //writing VTK file fprintf(fpo,"# vtk DataFile Version 3.0\n"); fprintf(fpo,"vtk output\n"); fprintf(fpo,"ASCII\n"); fprintf(fpo,"DATASET UNSTRUCTURED_GRID\n"); fprintf(fpo,"PINTS %ld float\n",newline_count); fseek(fpi,0,SEEK_SET); while (fscanf(fpi,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!=EOF) { printf("%f,%f,%f,%d,%d,%d\n", x, y, z, r, g, b); fprintf(fpo,"%f %f %f\n",x,y,z); } fprintf(fpo,"CELLS %ld %ld\n",newline_count,newline_count*2); for(i=0;i