![]() |
| ||
| Dynamic Array, Writing to CSV, Floating Point ?'s Below is a program in C that I am trying to use to read in a spreadsheet (in CSV form), which I will eventually be doing calculations on and then writing out to a new file. I'm currently trying to figure out the following three things: 1) How to make it so that the matrix is dynamically allocated memory. Right now it's set to be 10 x 10, but I want it to read the number of items between comma's as the width and the number of rows as the height. Can I just add the number of occurences of commas and add 1 to the total to get the width? 2) Right now it just writes out the data that it's reading in from the file, but could someone point me in the right direction for writing to a new CSV file with the - eventually modified - data? 3) I want to work with floating point numbers to two spaces (i.e. 10.14), where should I be defining that? I tried "float array[10][10] and a few other things, but wasn't too successful. I'm pretty new to C, and these forums have been a huge help so far, thanks to everyone who's contributed to any of the threads. #include <stdio.h> Sample data I'm using: 2018,015,110.87,110.9,110.87,110.9,9,9,9,9 2018,020,110.9,110.9,110.86,110.88,5,5,5,5 20,025,110.87,110.88,110.85,110.88,7,7,7,7 2018,030,110.88,110.95,110.87,110.93,10,10,10,10 18,035,110.93,110.94,110.91,110.92,9,9,9,9 20,040,110.92,110.93,110.9,110.91,11,11,11,11 218,045,110.91,110.93,110.91,110.91,6,6,6,6 20218,050,110.91,110.93,110.9,110.9,10,10,10,10 218,055,110.9,110.93,110.9,110.92,11,11,11,11 20218,100,110.89,110.93,110.9,110.94,12,12,12,12 Thanks for any help! Nolan |
| ||
| Re: Dynamic Array, Writing to CSV, Floating Point ?'s |
| ||
| Re: Dynamic Array, Writing to CSV, Floating Point ?'s Quote:
I'm trying to understand a process...I searched around for code on how to read in CSV files, found what I posted, attempted to change what I needed to to make floating point numbers, was unsuccessful, signed up for a message board, asked how to work with floating point numbers and then I realized I would need to output to CSV, so I asked about how to do that. So basically...from the beginning I knew nothing about working with CSV files, so instead of asking how to do the above, I researched sites to find it. If you'd rather me waste more of your time by asking how to do the above, I'd be glad to. I've been working on the code today and still to no avail. It's a lot more efficient and effective to learn from others than screw up code for 2 weeks straight before giving up on a program. At least that's how I see it. I'm not looking for you to write my code, I'm looking for someone who can point me in a right direction. Thanks for anyone who can offer some help |
| ||
| Re: Dynamic Array, Writing to CSV, Floating Point ?'s though I did just see that you offered advice on the other forum, so thank you. I didn't realize that people would take such offense to asking advice on pre-written code on multiple boards and will point out sources in the future. I made the basic assumption that the more people who saw the code, the more advice I'd get. |
| ||
| Re: Dynamic Array, Writing to CSV, Floating Point ?'s >though I did just see that you offered advice on the other forum, so thank you. Now you yourself have tasted the confusion of cross posting. >I didn't realize that people would take such offense to asking advice on pre-written code on multiple boards and will point out sources in the future. Perhaps I was too jumpy as well. But discovering code I wrote being posted here after it was made incorrect, and then seeing an identical thread elsewhere... I find cross-posting to be rude. And at first I thought you just grabbed the code and didn't acknowledge that it wasn't yours (I read code before the text, usually). I've seen folks copy my code and say, "Hey, look, I wrote this but I need help making a little change..." >I made the basic assumption that the more people who saw the code, the more advice I'd get. Perhaps. Not all the advice you get may be in regard to the code, no? If you cross-post, that's your choice. I suggest at least updating each cross-post with links to where it is cross-posted. Otherwise someone might spend a fair amount of time trying to help, only to be handed one of those "thanks, but I got it working" [with the help from one of the cross posts]. But back to the original issue. What is the big picture? Do you even need an array, or could you simply read, modify and write each value? Is the matrix rectangular? Is the size fixed or could it vary? |
| |||
| Re: Dynamic Array, Writing to CSV, Floating Point ?'s Quote:
Quote:
Quote:
date, time, price, price, price, price, volume, So it will always be 7 columns, but the number of rows will always vary. The reason I thought I would need an array is to go about sorting the columns by date and time, though I could also do that in excel before saving the .csv file. A problem I'm dealing with is that there is more than 65,000 rows of data, so I have to use rows A-G, then move to H-N for the rest, and so on. At that point I have to format the date from mm/dd/yyyy to yyyymmdd and the time from standard to military (which I assume won't be hard to just have done in the program as well). I then copy all of the rows into notepad where the file is then complete for my purposes and moved on to someone else. |
| ||
| Re: Dynamic Array, Writing to CSV, Floating Point ?'s Also, I guess there's no real reason why this couldn't be done in C++. Do you see some specific advantages to going that route? |
| ||
| Re: Dynamic Array, Writing to CSV, Floating Point ?'s Vectors, strings vs dynamic allocation in C was the reason for that. |
| |||
| Re: Dynamic Array, Writing to CSV, Floating Point ?'s Quote:
Quote:
Quote:
|
| ||
| Re: Dynamic Array, Writing to CSV, Floating Point ?'s the number of rows is not fixed |
| All times are GMT -4. The time now is 7:23 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC