Advertisement
d10070dd

csvread2

Sep 14th, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.     int r,g,b;
  6.     int count;
  7.     FILE *fp;
  8.     float x,y,z;
  9.  
  10.     if(argc!=2)
  11.     {
  12.         fprintf(stderr,"Usage: %s (1)InputFileName.txt\n",argv[0]);
  13.  
  14.         return 0;
  15.     }
  16.  
  17.  
  18.     if((fp=fopen(argv[1],"r"))==NULL)
  19.     {
  20.         printf("The file can't be opened. The program is exit.\n");
  21.  
  22.         return 0;
  23.     }
  24.  
  25.     count=0;
  26.  
  27.     while (fscanf(fp,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!= EOF)
  28.     {
  29.         printf("%f,%f,%f,%d,%d,%d\n", x, y, z, r, g, b);
  30.  
  31.         count=count+1;
  32.     }
  33.  
  34.     printf("total=%d\n",count);
  35.  
  36.     fclose(fp);
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement