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


Groups > comp.lang.c > #101973

Re: Program to check for valid names

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Program to check for valid names
Date 2017-01-16 16:23 +0000
Organization A noiseless patient Spider
Message-ID <878tqbht32.fsf@bsb.me.uk> (permalink)
References (5 earlier) <o5ibbs$ube$1@dont-email.me> <104b2893-8798-4902-9f07-07b08ef3e91c@googlegroups.com> <d4e7ab85-bc71-462f-92a2-f603108cfac4@googlegroups.com> <o5ifr1$e6f$1@dont-email.me> <52e7636c-ebf6-4eea-b50e-f2747914c6ed@googlegroups.com>

Show all headers | View raw


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

> On Monday, January 16, 2017 at 3:56:44 PM UTC+3, Richard Heathfield wrote:
>> On 16/01/17 12:21, Alla _ wrote:
>> <snip>
> <snip>
> I have forgotten to attach a program. Please, ignore one tiny additional
> function I have added. I need it for further work.

But the new function is wrong (it has a bug) but I don't really think
you will need it.

<snip>
> /** Function to compare names to
>     the required set of names 
>  **/
> bool valid_names(const char *line)
> {
>     char *names [] = { "Years", "Sales", "Cost of Goods Sold", "COGS",
>         "Gross Profit", "\"Selling, General, and Admin Exp\"", "SG&A",
>         "Operating Income before Depr", "Operating Income before Depreciation",
>         "Depreciation and Amortization", "Operating Profit", "Interest Expense",
>         "Other Gains and Losses", "Pretax Income", "Income Tax Expense", "Net Income",
>         NULL};
>     
>     size_t i = 0;
>     while(names[i])
>     {
>         if(!strncmp(names[i], line, strlen(names[i])))
>         {
>             printf("Names[%zu] = %zu\n", i, strlen(names[i]));
>             return true;
>         }
>         i++;
>     }
>     return false;
> }

According to your specification you don't need to search this list.
Your original plan was that the names must occur in order:

|  (1) check if row names completely correspond to the required ones,
|  no more or less of those - for this I assume I need an array
|  of required row names, and when reading each line from the 
|  file, make sure that line 1 row name equals the first name in 
|  the array, etc.

> /** Function to find first number **/
> char *find_first_number(char *line)
> {
>     while(!isdigit(*line))
>         line++;
>     return line;

When the execution gets here (as it must if the program is to work at all)
what one thing do you know with absolute certainty?  Do you see any
program with that fact?

> }

I don't think this function will help nearly as much as knowing where to
look for the first number.  The "valid_names" function could help you
with that.  Can you see how?

-- 
Ben.

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


Thread

Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-14 04:35 -0800
  Re: Program to check for valid names Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-14 15:02 +0000
    Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-14 07:29 -0800
      Re: Program to check for valid names supercat@casperkitty.com - 2017-01-14 10:17 -0800
      Re: Program to check for valid names Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-14 18:29 +0000
        Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 02:16 -0800
          Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 11:40 +0000
            Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 03:50 -0800
              Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 04:21 -0800
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 12:56 +0000
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 12:59 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 05:03 -0800
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 13:06 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 06:40 -0800
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 15:03 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 08:29 -0800
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 16:42 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 09:03 -0800
                Re: Program to check for valid names Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-16 17:17 +0000
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 17:20 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 09:26 -0800
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 17:18 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 09:23 -0800
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 17:30 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 06:42 -0800
                Re: Program to check for valid names Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-16 16:23 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 08:46 -0800
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 09:33 -0800
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-16 17:37 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 09:54 -0800
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-17 03:44 -0800
                Re: Program to check for valid names Barry Schwarz <schwarzb@dqel.com> - 2017-01-17 08:16 -0800
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-18 10:21 -0800
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-18 10:32 -0800
                Re: Program to check for valid names Richard Heathfield <rjh@cpax.org.uk> - 2017-01-18 19:38 +0000
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-18 12:52 -0800
                Re: Program to check for valid names Barry Schwarz <schwarzb@dqel.com> - 2017-01-18 18:52 -0800
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-20 02:00 -0800
                Re: Program to check for valid names Barry Schwarz <schwarzb@dqel.com> - 2017-01-20 12:09 -0800
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-20 02:45 -0800
                Re: Program to check for valid names Barry Schwarz <schwarzb@dqel.com> - 2017-01-20 12:24 -0800
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-21 09:02 -0800
                Re: Program to check for valid names Barry Schwarz <schwarzb@dqel.com> - 2017-01-18 18:05 -0800
                Re: Program to check for valid names Barry Schwarz <schwarzb@dqel.com> - 2017-01-16 10:23 -0800
                Re: Program to check for valid names Alla _ <modelling.data@gmail.com> - 2017-01-16 23:03 -0800
                Re: Program to check for valid names Barry Schwarz <schwarzb@dqel.com> - 2017-01-17 00:19 -0800
  Re: Program to check for valid names Barry Schwarz <schwarzb@dqel.com> - 2017-01-14 18:23 -0800

csiph-web