1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <fstream>
#include <vector>
#include <stdio.h>
using namespace std;
struct record
{
int a, b, c;
char d;
};
int main(void)
{
const char filename[] = "C:\\Users\\rhcr56\\Documents\\C++\\ANG_snp_list_120109.csv";
FILE *file = fopen(filename, "r");
if ( file != NULL )
{
char line [ 80 ];
struct record record [ 54444 ];
size_t count, i = 0;
while ( i < sizeof record/ sizeof *record )
{
if ( fgets(line, sizeof line, file) == NULL )
{
break;
}
if ( sscanf(line, "%d,%d,%d,%s", &record[i].a, &record[i].b,
&record[i].c, &record[i].d) == 4 )
{
++i;
}
}
fclose(file);
for ( count = i, i = 0; i < count; ++i )
{
printf("record[%lu]: a = %d, b = %d, c = %d, d = %s\n",
(long unsigned)i, record[i].a, record[i].b, record[i].c,
record[i].d);
}
}
else
{
perror(filename);
}
system("PAUSE");
return 0;
}
|