Advertisement
d10070dd

text2binary-vtk-polygons-x

Nov 19th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. /*********************************************************************************
  2.  Input file : ASCII - space separated file (x,y,z)
  3.  Processing : ascii to binary
  4.  Output file : binary
  5.  
  6.  ***********************************************************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.     //Decralation of variables
  15.     FILE *fpi,*fpo;
  16.     int id;
  17.     int points[3];
  18.    
  19.     int num=685;
  20.    
  21.     //Open CSV file
  22.     if((fpi=fopen(argv[1],"r"))==NULL)
  23.     {
  24.         printf ("The file can't be opened. The program is exit.\n");
  25.        
  26.         return 0;
  27.     }
  28.    
  29.     //Open VTK file for save
  30.     if((fpo=fopen(argv[2],"wb"))==NULL)
  31.     {
  32.         printf("The file can't be opened. The program is exit.\n");
  33.        
  34.         return 0;
  35.     }
  36.    
  37.     //points=(float *)malloc(num*3*sizeof(float));
  38.     //fread((float *)points,sizeof(float),1,fpi);
  39.    
  40.    
  41.     while(fscanf(fpi,"%d %d %d %d",&id,&points[0],&points[1],&points[2])!=EOF)
  42.     {
  43.  
  44.         printf("%d %d %d\n",points[0],points[1],points[2]);
  45.        
  46.         fwrite(&points,sizeof(int),3,fpo);
  47.         //fwrite(&x,sizeof(float),1,fpo);
  48.         //fwrite(&y,sizeof(float),1,fpo);
  49.         //fwrite(&z,sizeof(float),1,fpo);
  50.     }
  51.    
  52.     fclose(fpi);
  53.     fclose(fpo);
  54.    
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement