Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thchang/csvtomatrix
Import a matrix from a CSV into a C array, and store in row-major ordering.
https://github.com/thchang/csvtomatrix
c csv
Last synced: 12 days ago
JSON representation
Import a matrix from a CSV into a C array, and store in row-major ordering.
- Host: GitHub
- URL: https://github.com/thchang/csvtomatrix
- Owner: thchang
- Created: 2020-12-04T01:18:27.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-12-04T02:17:51.000Z (about 4 years ago)
- Last Synced: 2024-10-09T12:58:55.460Z (4 months ago)
- Topics: c, csv
- Language: C
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CSVtoMatrix
One day I needed to load a matrix from a CSV file into a C array.
I looked around the internet to borrow someone else's solution, but
I couldn't easily find an existing solution for this simple and
common task, which I think is surprising. (I'm sure someone has
posted about this before, I just couldn't easily find it). So I
wrote my own solution. Maybe the next guy/gal will find this and
save an hour :)Note, there is no support for white spaces, this is just a simple demo...
```
/*
* Function: readCSV
* -----------------
* read a nXm matrix from a CSV file into a flat array in row-major ordering
*
* n: the number of rows
*
* m: the number of cols
*
* fp: pointer to FILE object for the CSV file containing (one row per line)
*
* mat: pointer to a block of memory of size sizeof(double)*n*m, into which
* the matrix will be loaded on output
*/
void readCSV(int n, int m, FILE *fp, double *mat)
```## Contents
There are 4 files:
* `README.md` is this file
* `readCSV.c` is the source file
* `matrix.csv` is a sample matrix
* `Makefile` is a sample GNU makefile