Advertisement
d10070dd

text2binary

Oct 1st, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. int main(int argc,char *argv[])
  7. {
  8.     FILE *fpi,*fpo;
  9.     int i,j,k,face,vertex,point;
  10.     float data;
  11.     char line[6];
  12.  
  13.     if(argc!=6)
  14.     {
  15.         fprintf(stderr,"Usage: %s 5m_mesh_data.lem,5m_mesh_data.raw\n",argv[0]);
  16.         exit(1);
  17.     }
  18.     printf("OPEN FILE NAME:%s\n",argv[1]);
  19.  
  20.     if((fpi=fopen(argv[1],"r"))==NULL)
  21.     {
  22.         fprintf(stderr,"Can not open\n");
  23.         exit(1);
  24.     }
  25.  
  26.     if((fpo=fopen(argv[2],"wb"))==NULL)
  27.     {
  28.         fprintf(stderr,"Can not open\n");
  29.         exit(1);
  30.     }
  31.  
  32.     face=atoi(argv[3]);
  33.     vertex=atoi(argv[4]);
  34.     point=atoi(argv[5]);
  35.     for(i=0;i<face;i++)
  36.     {
  37.         for (j=0;j<vertex;j++)
  38.         {
  39.             for (k=0;k<point;k++)
  40.             {
  41.                 fseek(fpi,5*k+j*17+i*68,SEEK_SET);
  42.  
  43.                 fgets(line, 6, fpi);
  44.                 data=atof(line);
  45.                 printf("%f\n",data);
  46.                 fwrite(&data,sizeof(float),1,fpo);
  47.             }
  48.         }
  49.     }
  50.  
  51.     fclose(fpi);
  52.     fclose(fpo);
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement