Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #98801

Re: Program to create csv file and write into it

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Program to create csv file and write into it
Date 2016-12-11 14:43 +0000
Organization A noiseless patient Spider
Message-ID <877f76zftq.fsf@bsb.me.uk> (permalink)
References <6b201709-fae0-4a06-9783-af485e4040bf@googlegroups.com> <87wpf71pp6.fsf@bsb.me.uk> <08c753c8-4a52-4c95-9d33-15647011cbcf@googlegroups.com> <87shpuzoch.fsf@bsb.me.uk> <5494a032-9185-44f6-8bb3-79c24bc6a786@googlegroups.com>

Show all headers | View raw


Alla _ <modelling.data@gmail.com> writes:

> On Sunday, December 11, 2016 at 2:39:51 PM UTC+3, Ben Bacarisse wrote:
>> Alla _ <modelling.data@gmail.com> writes:
>> <snip>
>> > Oh, great ))) I am still far off with my assumptions. 
>> >
>> > (1) Yes, I have not repeated my goal here; I should have.
>> > I am planning to:
>> > # take a few excel spreadsheets, which contain financial statements;
>> > convert them into csv format
>> 
>> OK.  This part is not in C right?
>> 
>> > # read data from those csv files using C language
>> 
>> OK.
>> 
>> > # process that data (a few functions) to compute pro forma financial
>> > statements, and, if I find that to be not big enough,
>> 
>> OK, stop!  For my sake, take a simple goal and run with it.  Can you
>> show me one of these pro forma financial statements?  You know what you
>> mean, but it would help keep things concrete if I knew what the output
>> might be like.
>
> Of course. First in words (a simplified version):
<snip>
> Here is how common size statement looks like in csv format:
>
> Income Statement,2011,2012,Avg
> Sales,1.00,1.00,1.000
> Cost of Goods Sold,0.62,0.65,0.635
>   Gross Profit,0.38,0.35,0.365
> SG&A,0.24,0.22,0.230
>   Operating Income before Depr,0.14,0.13,0.135
> Depreciation and Amortization,0.02,0.02,0.020
>   Operating Profit,0.12,0.11,0.115
> Interest Expense,0.00,0.00,0.000
> Other Gains and Losses,0.00,0.01,0.005
>   Pretax Income,0.12,0.10,0.110
> Income Tax Expense,0.05,0.04,0.043
>   Net Income,0.07,0.06,0.067
>
> Here is part of the final pro forma statement (actually
> these are just numbers, so formulas are not seen of
> course):
> INCOME STATEMENT,2016,2017,2018
> Sales,"1,062","1,252","1,587"
> Cost of Goods Sold,654,814,"1,009"
>   Gross Profit,408,438,578
> "Selling, General, and Admin Exp",254,271,364
>   Operating Income before Depr,154,167,214
> Depreciation and Amortization,25,31,38
>   Operating Profit,129,136,176
> Interest Expense,4,3,3
> Other Gains and Losses,0,7,10
>   Pretax Income,125,126,163
> Income Tax Expense,55,52,65
>   Net Income,70,74,98
>
> I am not sure if I managed to explain what I would like to achieve. I will be 
> happy to give more details if required.

Thanks.  There some other inputs mentioned (a user file for example) so
I'm not sure I fully understand even the data sources, but the gist of
it is simple enough.

>> <snip>
>> > Therefore, the program I have posted here is supposed to be one of the 
>> > functions, which will later on take already computed pro forma data and
>> > write it into a csv file.

I would then have expected to see a function something like this:

  int write_data_in_csv_format(FILE *fp, const Data_Item *rows, size_t n_rows)

That's the part you will be able to take forward into the bigger program.

<snip>
>> So the posted program was a trial of some sort?  I see.  Do you want to
>> get it working before moving on?  If so, you need to describe the intent
>> of that trial program and we can forget (for the moment) the goals you've
>> set yourself above.
>> 
> Yes, of course. Not only because I will use it, but also because this is how
> I will learn. I need to make sure this program works the way it is
> intended.

Well I'd start with with a write_csv_file function of some sort.  It's
not obvious exactly how much sophistication you need in the data
structure, so you could start with just a simple array of rows like I
did above.

If the task gets complex enough, you can wrap the rows and the count of
the rows (and other stuff) into a fully-fledged data frame later, but
I'd start simple.

Can you come up with a suitable Data_Item structure?  And what about the
write_data_in_csv_format function -- can you write that?  Note that I
don't mean finish it.  I mean only the first refinement of it.  In
top-down design you write the function assuming that you have on or more
very useful functions to help you.  You speculate: "if only I had a
function that did X, I could write the current function very easily".
You write assuming a function that does X and move on to writing that
function.  Eventually you end up with things like "if only I have a
function that could output a string... oh, I do: fputs".

<snip>
-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-10 09:30 -0800
  Re: Program to create csv file and write into it Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 20:42 +0000
    Re: Program to create csv file and write into it Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-10 15:56 -0500
      Re: Program to create csv file and write into it Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 21:08 +0000
    Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-10 23:48 -0800
      Re: Program to create csv file and write into it Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-11 00:01 -0800
      Re: Program to create csv file and write into it Keith Thompson <kst-u@mib.org> - 2016-12-11 01:12 -0800
      Re: Program to create csv file and write into it Keith Thompson <kst-u@mib.org> - 2016-12-11 01:27 -0800
        Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-11 04:50 -0800
          Re: Program to create csv file and write into it Barry Schwarz <schwarzb@dqel.com> - 2016-12-11 09:42 -0800
            Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 00:13 -0800
              Re: Program to create csv file and write into it Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 08:34 +0000
                Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 00:50 -0800
                Re: Program to create csv file and write into it Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 09:02 +0000
                Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 02:52 -0800
                Re: Program to create csv file and write into it Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 10:59 +0000
                Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 03:23 -0800
          Re: Program to create csv file and write into it mx2927 <mx2927@gmail.com> - 2016-12-11 20:44 +0100
            Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-11 23:57 -0800
              Re: Program to create csv file and write into it Barry Schwarz <schwarzb@dqel.com> - 2016-12-12 01:06 -0800
      Re: Program to create csv file and write into it Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 11:39 +0000
        Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-11 04:47 -0800
          Re: Program to create csv file and write into it Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 14:43 +0000
            Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 00:56 -0800
      Re: Program to create csv file and write into it Barry Schwarz <schwarzb@dqel.com> - 2016-12-11 09:38 -0800
        Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 00:44 -0800
          Re: Program to create csv file and write into it Richard Heathfield <rjh@cpax.org.uk> - 2016-12-12 08:48 +0000
          Re: Program to create csv file and write into it Barry Schwarz <schwarzb@dqel.com> - 2016-12-12 01:19 -0800
            Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-12 02:30 -0800
            Re: Program to create csv file and write into it Manfred <noname@invalid.add> - 2016-12-12 15:10 +0100
              Re: Program to create csv file and write into it Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-12 12:35 -0800
  Re: Program to create csv file and write into it Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-10 14:29 -0800
    Re: Program to create csv file and write into it Alla _ <modelling.data@gmail.com> - 2016-12-10 23:57 -0800
      Re: Program to create csv file and write into it Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-11 00:33 -0800
        Re: Program to create csv file and write into it Keith Thompson <kst-u@mib.org> - 2016-12-11 01:19 -0800

csiph-web