Advertisement
SUGIYAMA

☆txt_to_txt2

Nov 15th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.  
  6.     //Decralation of variables
  7.     int i;
  8.     int r,g,b;
  9.     unsigned long newline_count_1=0,newline_count_2=0,lines;
  10.     FILE *fpi1,*fpo;
  11.     float x,y,z;
  12.     float nx,ny,nz;
  13.     float fnx,fny,fnz;
  14.     unsigned char ux,uy,uz;
  15.     unsigned char unx,uny,unz;
  16.  
  17.     if(argc!=3)
  18.     {
  19.         fprintf(stderr,"Usage: %s (1)CSV1File\n(2)CSV2File\n(3)VTKFile\n",argv[0]);
  20.  
  21.         return 0;
  22.     }
  23.  
  24.     printf("Open CSV1 File\n");
  25.     //Open CSV1 file
  26.     if((fpi1=fopen(argv[1],"r"))==NULL)
  27.     {
  28.         printf("The file can't be opened. The program is exit.\n");
  29.  
  30.         return 0;
  31.     }
  32.  
  33.     //Open VTK file for save
  34.     if((fpo=fopen(argv[2],"w"))==NULL)
  35.     {
  36.         printf("The file can't be opened. The program is exit.\n");
  37.  
  38.         return 0;
  39.     }
  40.  
  41.     //count how many lines
  42.     /*
  43.     while((c==fgetc(fpi))!=EOF
  44.     {
  45.         if(c=='\n')
  46.             newline_count++;
  47.     }
  48.     */
  49.  
  50.     printf("CSV1 File\n");
  51.    
  52.     while (fscanf(fpi1,"%f %f %f %d %d %d %f %f %f",&x, &y, &z, &r, &g, &b, &nx, &ny, &nz)!= EOF)
  53.     {
  54.         printf("%f %f %f\n",x,y,z);
  55.             fnx=(nx+1)*255/2;
  56.             fny=(ny+1)*255/2;
  57.             fnz=(nz+1)*255/2;
  58.             unx=(unsigned char)fnx;
  59.             uny=(unsigned char)fny;
  60.             unz=(unsigned char)fnz;
  61.             fprintf(fpo,"%f %f %f %d %d %d\n",x,y,z,unx,uny,unz);
  62.     }
  63.  
  64.    
  65.  
  66.     fclose(fpi1);
  67.     fclose(fpo);
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement