#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MATROW 433
#define MATCOL 3
#define MAXCHAR 1024
#define MAXCOUNT 1000000
#pragma warning(disable:4996)
void read_csv(const char* path, float float_mat[MATROW][MATCOL], int *rows, int *cols)
{
FILE *fp;
char row[MAXCHAR];
char *token;
fp = fopen(path, "r");
int linecount = 0, i = 0, j = 0;
while (fgets(row, MAXCHAR, fp))
{
//从第0行开始读
linecount++;
if (linecount > MAXCOUNT)
break;
token = strtok(row, ",");
j = 0;
while (token)
{
float_mat[i][j++] = atof(strdup(token));
token = strtok(NULL, ",");
}
i++;
}
fclose(fp);
*rows = i;
*cols = j;
// 打印转换后的浮点数数组
/*for (int p = 0; p < *rows; p++)
{
for (int q = 0; q < *cols; q++)
{
printf("%f ", float_mat[p][q]);
}
printf("\n");
}*/
}
void main()
{
int rows, cols;
float means[MATROW][MATCOL];
read_csv("..//parameter_means//0.csv", means, &rows, &cols);
}
06-06
2466