How to read and use data from CSV files? [duplicate] - c

This question already has answers here:
How can I read and parse CSV files in C++?
(39 answers)
Closed 9 years ago.
I have CSV files that contain 2 columns of x and y coordinates, that are the positions of particles.
I want to read these files and be able to use the data inside to calculate a function (I mean I want use the coordinates to calculate the pair distribution function g(r)).
I have the algorithm to calculate this function but I need help with how to access the CSV files, and be able to read and use the data inside. I'm new to programing in C, can anyone help?

You use a library, such as libcsv.

Related

Any append (Python) or push_back (C++) equivalent in C? [duplicate]

This question already has an answer here:
Python-like array filling - C equivalent
(1 answer)
Closed 2 years ago.
I'm looking for an "append" (Python) or "push_back" (C++) equivalent in C to fill an array of strings (char). Does it exists?
The question doesn't make sense because you cannot add elements to an array in C. In C, you set the size of the array when you create it, and the size cannot change.
If you want to "append", you have to create a big array (e.g. 1000 items), and use a separate variable to remember how many items you're actually using (the rest are spare).

How to read a file backwards in C? [duplicate]

This question already has answers here:
Reading a text file backwards in C
(5 answers)
Closed 7 years ago.
I am reading a one line string from a file and I need to read it into an array in reverse order. How can I accomplish this?(I am using C).
So, my file looks like:
ACGTGCGATCGATCGATCGATATCGATCGTCTGCTTAAGCTC
And I want my array of chars that I read into to look like:
CTCGAA...
Thanks in advance.
Read the file front-to-back into the array, then reverse the contents of the array in place. That's the best way to do that as reading a file backwards is a very slow operation.

Put BMP image into 2D array and edit RGB values in C [duplicate]

This question already has answers here:
Writing BMP image in pure c/c++ without other libraries
(13 answers)
Closed 7 years ago.
Okay guys, I am new to C and I am a trying to construct a 2D array that will hold a BMP image and be able to edit the RGB values. I haven't been able to find anything online about how to access the RGB values or how to put this image in the 2D array and I am really stuck as to where to start. HELP!!!!
See the reference Writing BMP image in pure c/c++ without other libraries of Ed Heal. Things to note:
Define the structures. Don't use arrays of unsigned chars to make the headers as in the referenced post.
Both in reading and writing, take care to fill the scanlines. They must be a multiple of four, so the last bytes may not be pixels and contain garbage.
See also my earlier post What is wrong with this code for writing grey-scale bmp from an image RGB bmp pure C - Windows OS which contains the headers and can serve as a partial example.

Telling when file was last accessed in C [duplicate]

This question already has an answer here:
Determining if file has been copied or not in C [closed]
(1 answer)
Closed 9 years ago.
In Windows, if you go to a file's properties it shows the last access time right under the time last modified. This changes when I copy it.
How do I view this in C?
You can use the GetFileTime() function to get it. This MSDN article has more details about file times.
The portable way of getting the last modified timestamp is by using fstat or stat. If you want to go the Windows-only route (by directly calling a Windows API), see #xxbbcc's answer.
See How can I get a file's size in C++? for a short piece of sample code that uses stat/fstat - only change for your purpose is that you'll want to read the time_t st_mtime field.

Read a binary file in Scala [duplicate]

This question already has answers here:
Parsing of binary data with scala
(5 answers)
Closed 9 years ago.
I have some binary files which are written by a Java application in the following way:
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(complete_path_to_file)));
dos.writeInt(aInteger);
dos.writeLong(aLong);
dos.writeFloat(aFloat);
dos.close();
Now, I'd like to read this kind files in a Scala framework but I really don't have any ideas about how to do that.
Could you help me?
Reading it using the same classes and methods you'd use in Java is probably going to be the most error-free, as you have a direct correspondence between read and write.
You can also use Scala I/O, which is the best library for file I/O for Scala -- and a possible addition to the standard library in the future.
Then there's sbinary, where less concern is given to I/O itself, and more concern is given to describing the binary record.

Resources