Re: CSV Data to Binary File

2014-08-07 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 7 August 2014 at 15:11:48 UTC, TJB wrote: Here is a snippet of my csv data: 34220, 37, 371200, 1, 1, 12, N, 34220, 369000, 372500, 1, 11, 12, P, 34220, 37, 371200, 1, 2, 12, N, I can't help but think somehow that as long as the data is numbers or words, that scanf would

Re: CSV Data to Binary File

2014-08-07 Thread via Digitalmars-d-learn
On Thursday, 7 August 2014 at 17:12:35 UTC, Marc Schütz wrote: This align the struct as a whole, and all its fields at byte boundaries. Without the second `align(1)`, there should be a gap between `mode` and `ex`. Strangely enough, when I test it, there's none. Will have to ask... Sorry, shou

Re: CSV Data to Binary File

2014-08-07 Thread via Digitalmars-d-learn
On Thursday, 7 August 2014 at 16:08:01 UTC, TJB wrote: Thanks Marc. Not sure what to do here. I need to the binary data to be exactly the number of bytes as specified by the struct. Something else: The `align(1)` on your type definition specifies the alignment of the entire struct, but has no

Re: CSV Data to Binary File

2014-08-07 Thread via Digitalmars-d-learn
On Thursday, 7 August 2014 at 16:08:01 UTC, TJB wrote: Thanks Marc. Not sure what to do here. I need to the binary data to be exactly the number of bytes as specified by the struct. How to handle the conversion from string to char[]? Well, in your CSV data, they don't have the right length,

Re: CSV Data to Binary File

2014-08-07 Thread TJB via Digitalmars-d-learn
Thanks Marc. Not sure what to do here. I need to the binary data to be exactly the number of bytes as specified by the struct. How to handle the conversion from string to char[]? TJB (You forgot to include the error. For other readers: It fails to compile with "template std.conv.toImpl cannot

Re: CSV Data to Binary File

2014-08-07 Thread via Digitalmars-d-learn
On Thursday, 7 August 2014 at 15:14:00 UTC, TJB wrote: align(1) struct QuotesBin { int qtim; int bid; int ofr; int bidsiz; int ofrsiz; short mode; char[1] ex; char[4] mmid; } Thanks! (You forgot to include the error. For other readers: It fails to compile with "template std.co

CSV Data to Binary File

2014-08-07 Thread TJB via Digitalmars-d-learn
I am trying to read data in from a csv file into a struct, and then turn around and write that data to binary format. Here is my code: import std.algorithm; import std.csv; import stdio = std.stdio; import std.stream; align(1) struct QuotesBin { int qtim;9 int bid; int ofr; int bidsiz;

Re: CSV Data to Binary File

2014-08-07 Thread TJB via Digitalmars-d-learn
On Thursday, 7 August 2014 at 15:11:48 UTC, TJB wrote: I am trying to read data in from a csv file into a struct, and then turn around and write that data to binary format. Here is my code: import std.algorithm; import std.csv; import stdio = std.stdio; import std.stream; align(1) struct Quot