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


Groups > comp.lang.c > #99663

Re: [File Handling] fread(), fseek() and text file

From Richard Heathfield <rjh@cpax.org.uk>
Newsgroups comp.lang.c
Subject Re: [File Handling] fread(), fseek() and text file
Date 2016-12-16 17:00 +0000
Organization Fix this later
Message-ID <o316fv$dr5$1@dont-email.me> (permalink)
References (2 earlier) <1d89377e-acd5-47d7-abca-1a3d28b65678@googlegroups.com> <o30s2a$88l$1@dont-email.me> <027c95a8-183b-4d34-8214-cdc41be578b6@googlegroups.com> <o310kr$o5b$1@dont-email.me> <703f5537-45b1-4946-af97-3615c15dbbd3@googlegroups.com>

Show all headers | View raw


On 16/12/16 16:54, Dexterr wrote:
> Mr Richard, I have put it into a struct. What you think ? ;)

I think you haven't been paying attention.

> void readSortFunction()

Putting it in a function is a good idea. Calling that function 
readSortFunction is not such a good idea, since all functions are 
functions, so "Function" doesn't add anything to the reader's knowledge, 
and "Sort" doesn't describe what it does.

void read_component_file(void)

would be better.

> {
> 	FILE *fp = fopen(FILENAME, "r");
> 	Components *series_connection = (Components*) malloc(sizeof *series_connection);

Better than before, but lose the cast. It's completely unnecessary.

And, *yet again*, I suggest that you TEST the pointer before using it. 
If you must use a pointer, that is. I don't see why you need to allocate 
this space dynamically.

Apart from that, it looks fine to me.

To improve it, separate the three parts of the process into three parts:

1) read the line
2) process the line
3) print the line

Three different functions.

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

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


Thread

[File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-16 01:10 -0800
  Re: [File Handling] fread(), fseek() and text file Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 09:59 +0000
    Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-16 05:28 -0800
      Re: [File Handling] fread(), fseek() and text file Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 14:02 +0000
        Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-16 06:30 -0800
          Re: [File Handling] fread(), fseek() and text file Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 15:20 +0000
            Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-16 08:54 -0800
              Re: [File Handling] fread(), fseek() and text file Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 17:00 +0000
                Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-16 09:32 -0800
                Re: [File Handling] fread(), fseek() and text file Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 17:38 +0000
                Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-16 10:03 -0800
                Re: [File Handling] fread(), fseek() and text file Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 18:40 +0000
                Re: [File Handling] fread(), fseek() and text file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 20:16 +0000
                Re: [File Handling] fread(), fseek() and text file Keith Thompson <kst-u@mib.org> - 2016-12-16 12:46 -0800
                Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-17 05:47 -0800
                Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-17 05:49 -0800
                Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-17 05:43 -0800
                Re: [File Handling] fread(), fseek() and text file Barry Schwarz <schwarzb@dqel.com> - 2016-12-17 08:48 -0800
                Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-17 12:03 -0800
                Re: [File Handling] fread(), fseek() and text file Keith Thompson <kst-u@mib.org> - 2016-12-17 12:22 -0800
                Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-17 12:23 -0800
  Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-17 12:26 -0800
    Re: [File Handling] fread(), fseek() and text file asetofsymbols@gmail.com - 2016-12-18 12:41 -0800
      Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-18 13:04 -0800
      Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-18 13:08 -0800
        Re: [File Handling] fread(), fseek() and text file asetofsymbols@gmail.com - 2016-12-19 06:14 -0800
          Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-19 10:38 -0800
            Re: [File Handling] fread(), fseek() and text file Richard Heathfield <rjh@cpax.org.uk> - 2016-12-19 18:51 +0000
              Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-19 11:14 -0800
                Re: [File Handling] fread(), fseek() and text file Richard Heathfield <rjh@cpax.org.uk> - 2016-12-19 19:35 +0000
          Re: [File Handling] fread(), fseek() and text file Dexterr <dejangru@gmail.com> - 2016-12-19 10:43 -0800

csiph-web