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


Groups > comp.lang.c > #98254 > unrolled thread

while loop vs do while loop reading from the file issue

Started byAlla _ <modelling.data@gmail.com>
First post2016-12-07 05:08 -0800
Last post2016-12-10 13:49 -0800
Articles 20 on this page of 180 — 22 participants

Back to article view | Back to comp.lang.c


Contents

  while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-07 05:08 -0800
    Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-07 13:46 +0000
      Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-07 07:27 -0800
        Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-07 16:17 +0000
    Re: while loop vs do while loop reading from the file issue Norbert_Paul <norbertpauls_spambin@yahoo.com> - 2016-12-07 14:54 +0100
      Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-07 07:29 -0800
    Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-07 17:20 +0000
      Re: while loop vs do while loop reading from the file issue "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-12-08 01:24 +0800
      Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-07 22:51 -0800
        Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-08 07:30 +0000
    Re: while loop vs do while loop reading from the file issue Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-07 12:45 -0500
      Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-07 17:50 +0000
        Re: while loop vs do while loop reading from the file issue Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-07 12:56 -0500
          Re: while loop vs do while loop reading from the file issue Barry Schwarz <schwarzb@dqel.com> - 2016-12-07 11:09 -0800
            Re: while loop vs do while loop reading from the file issue Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-07 14:38 -0500
              Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-07 23:29 -0800
                Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-08 07:35 +0000
                  Re: while loop vs do while loop reading from the file issue Manfred <noname@invalid.add> - 2016-12-08 16:57 +0100
                    Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-10 03:45 -0800
                  Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-09 01:08 -0800
                    Re: while loop vs do while loop reading from the file issue Barry Schwarz <schwarzb@dqel.com> - 2016-12-09 01:30 -0800
                    Re: while loop vs do while loop reading from the file issue Barry Schwarz <schwarzb@dqel.com> - 2016-12-09 01:50 -0800
                      Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-10 02:34 -0800
                        Re: while loop vs do while loop reading from the file issue fir <profesor.fir@gmail.com> - 2016-12-10 03:18 -0800
                        Re: while loop vs do while loop reading from the file issue Barry Schwarz <schwarzb@dqel.com> - 2016-12-10 07:43 -0800
                          Re: while loop vs do while loop reading from the file issue Manfred <noname@invalid.add> - 2016-12-10 18:21 +0100
                    Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-09 10:08 +0000
                      Re: while loop vs do while loop reading from the file issue Manfred <noname@invalid.add> - 2016-12-09 19:19 +0100
                      Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-10 03:56 -0800
                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-10 12:39 +0000
                          Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 14:58 +0000
                            Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-10 16:01 +0000
                              Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 19:47 +0000
                                Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-10 20:16 +0000
                                  Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 21:11 +0000
                                    Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-10 22:33 +0000
                                      Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 23:50 +0000
                                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-11 00:35 +0000
                                          Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-10 16:52 -0800
                                          Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 01:34 +0000
                                            Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-11 02:25 +0000
                                              Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 17:11 +0000
                                                Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-11 18:00 +0000
                                                  Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 19:44 +0000
                                                    Re: while loop vs do while loop reading from the file issue supercat@casperkitty.com - 2016-12-11 13:11 -0800
                                                    Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-11 22:40 +0000
                                                      Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-12 02:03 +0000
                                                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-12 12:53 +0000
                                                          Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-12 13:04 +0000
                                                          Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-12 13:27 +0000
                                                            Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-12 15:16 +0000
                                                              Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-12 23:00 +0000
                                                                Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 00:59 +0000
                                                                  Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-13 03:25 +0000
                                                                    Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 13:08 +0000
                                                                      Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-13 05:56 -0800
                                                                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 15:31 +0000
                                                                      Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-13 08:27 -0800
                                                                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 18:07 +0000
                                                                          Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-13 18:12 +0000
                                                                            Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 18:26 +0000
                                                                              Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-13 18:34 +0000
                                                                                Re: while loop vs do while loop reading from the file issue Gareth Owen <gwowen@gmail.com> - 2016-12-13 18:39 +0000
                                                                                Re: while loop vs do while loop reading from the file issue Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-13 13:47 -0500
                                                                                Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 19:03 +0000
                                                                                  Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-13 11:30 -0800
                                                                                    Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 20:10 +0000
                                                                                      Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-13 12:42 -0800
                                                                                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 21:29 +0000
                                                                                          Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-13 14:27 -0800
                                                                                            Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 22:56 +0000
                                                                                              Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-13 16:13 -0800
                                                                                                Re: while loop vs do while loop reading from the file issue supercat@casperkitty.com - 2016-12-14 07:33 -0800
                                                                                                  Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-14 09:05 -0800
                                                                                      Re: while loop vs do while loop reading from the file issue supercat@casperkitty.com - 2016-12-13 12:48 -0800
                                                                                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 21:37 +0000
                                                                                      Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 00:08 +0000
                                                                                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-14 01:24 +0000
                                                                                          Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-13 17:56 -0800
                                                                                            Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-14 02:33 +0000
                                                                                              Re: while loop vs do while loop reading from the file issue David Brown <david.brown@hesbynett.no> - 2016-12-14 10:03 +0100
                                                                                          Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 02:09 +0000
                                                                                            Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-14 12:24 +0000
                                                                                              Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-14 13:00 +0000
                                                                                                Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-14 08:54 -0800
                                                                                                  Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-14 17:01 +0000
                                                                                              Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 17:27 +0000
                                                                                                Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-14 20:24 +0000
                                                                                                  Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-15 10:47 +0000
                                                                                                    Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-15 11:54 +0000
                                                                                                      Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-15 04:02 -0800
                                                                                                      Re: while loop vs do while loop reading from the file issue supercat@casperkitty.com - 2016-12-15 07:40 -0800
                                                                                                      Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-15 11:48 -0800
                                                                                                      Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 01:52 +0000
                                                                                                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-16 11:09 +0000
                                                                                        Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-13 18:35 -0800
                                                                                    Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-13 20:18 +0000
                                                                                  Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-13 20:14 +0000
                                                                      Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-13 20:15 +0000
                                                                        Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-13 22:26 +0000
                                                                          Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 02:19 +0000
                                                                            Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-14 12:45 +0000
                                                                              Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-14 14:00 +0000
                                                                              Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 20:59 +0000
                                                                                Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-14 21:59 +0000
                                                                                  Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-15 02:42 +0000
                                                                                  Re: while loop vs do while loop reading from the file issue asetofsymbols@gmail.com - 2016-12-15 01:20 -0800
                                                                                    Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 09:28 +0000
                                                                                      Re: while loop vs do while loop reading from the file issue asetofsymbols@gmail.com - 2016-12-15 01:42 -0800
                                                                                        Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 09:53 +0000
                                                                                      Re: while loop vs do while loop reading from the file issue asetofsymbols@gmail.com - 2016-12-15 01:55 -0800
                                                                                      Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-15 02:03 -0800
                                                                                        Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 10:13 +0000
                                                                                          Re: while loop vs do while loop reading from the file issue Gareth Owen <gwowen@gmail.com> - 2016-12-15 22:05 +0000
                                                                                          Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-15 14:15 -0800
                                                                                        Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-15 10:44 +0000
                                                                                          Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-15 03:31 -0800
                                                                                            Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 01:11 +0000
                                                                                              Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-16 06:16 -0800
                                                                                                Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 17:24 +0000
                                                                                                  Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-16 09:53 -0800
                                                                                                    Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 20:38 +0000
                                                                                                      Re: while loop vs do while loop reading from the file issue Gareth Owen <gwowen@gmail.com> - 2016-12-16 21:13 +0000
                                                                                                      Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 21:50 +0000
                                                                                                        Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-16 14:19 -0800
                                                                                                          Re: while loop vs do while loop reading from the file issue supercat@casperkitty.com - 2016-12-16 15:03 -0800
                                                                                                          Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-17 02:20 +0000
                                                                                                            Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-17 02:21 -0800
                                                                                                              Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-17 12:14 +0000
                                                                                                                Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-17 04:56 -0800
                                                                                                                  Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-17 19:28 +0000
                                                                                                                  Re: while loop vs do while loop reading from the file issue Ike Naar <ike@iceland.freeshell.org> - 2016-12-17 22:51 +0000
                                                                                                              Re: while loop vs do while loop reading from the file issue Les Cargill <lcargill99@comcast.com> - 2016-12-17 11:45 -0600
                                                                                                                Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-17 19:42 +0000
                                                                                                                  Re: while loop vs do while loop reading from the file issue Les Cargill <lcargill99@comcast.com> - 2016-12-17 20:39 -0600
                                                                                                                    Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-18 10:49 +0000
                                                                                                Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-16 09:41 -0800
                                                                                                  Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-16 10:01 -0800
                                                                                                    Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-16 12:31 -0800
                                                                                                      Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-16 13:33 -0800
                                                                                                        Re: while loop vs do while loop reading from the file issue Ian Collins <ian-news@hotmail.com> - 2016-12-17 11:12 +1300
                                                                                                          Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-16 14:30 -0800
                                                                                                        Re: while loop vs do while loop reading from the file issue raltbos@xs4all.nl (Richard Bos) - 2016-12-20 11:16 +0000
                                                                                                          Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-20 03:29 -0800
                                                            Re: while loop vs do while loop reading from the file issue Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-12 16:13 -0800
                                                              Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-13 01:09 +0000
                                      Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-10 16:08 -0800
                                  Re: while loop vs do while loop reading from the file issue Sjouke Burry <burrynulnulfour@ppllaanneett.nnll> - 2016-12-11 01:31 +0100
                          Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-11 14:52 +0000
                            Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-11 15:26 +0000
                              Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-11 16:22 +0000
                                Re: while loop vs do while loop reading from the file issue BartC <bc@freeuk.com> - 2016-12-11 16:42 +0000
                                  Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-11 16:56 +0000
                                  Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-11 12:56 -0800
                              Re: while loop vs do while loop reading from the file issue supercat@casperkitty.com - 2016-12-11 08:55 -0800
                              Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 17:19 +0000
                      Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-10 04:09 -0800
                        Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 15:18 +0000
                          Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-10 07:30 -0800
                            Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 15:43 +0000
                            Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-10 14:56 -0800
                        Re: while loop vs do while loop reading from the file issue Barry Schwarz <schwarzb@dqel.com> - 2016-12-10 07:57 -0800
                    Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-09 11:40 -0800
                      Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-10 03:19 -0800
                        Re: while loop vs do while loop reading from the file issue Barry Schwarz <schwarzb@dqel.com> - 2016-12-10 07:49 -0800
                          Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 16:11 +0000
                            Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-10 14:45 -0800
                              Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-10 22:59 +0000
                Re: while loop vs do while loop reading from the file issue Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-08 11:26 -0500
                  Re: while loop vs do while loop reading from the file issue Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-08 11:48 -0500
                    Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-11 23:33 -0800
      Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-07 23:09 -0800
    Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-07 09:53 -0800
    Re: while loop vs do while loop reading from the file issue Barry Schwarz <schwarzb@dqel.com> - 2016-12-07 11:26 -0800
      Re: while loop vs do while loop reading from the file issue Keith Thompson <kst-u@mib.org> - 2016-12-07 11:50 -0800
      Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-07 23:12 -0800
        Re: while loop vs do while loop reading from the file issue Richard Heathfield <rjh@cpax.org.uk> - 2016-12-08 07:31 +0000
          Re: while loop vs do while loop reading from the file issue Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-08 11:00 +0000
            Re: while loop vs do while loop reading from the file issue Alla _ <modelling.data@gmail.com> - 2016-12-09 00:48 -0800
    Re: while loop vs do while loop reading from the file issue Siri Cruise <chine.bleu@yahoo.com> - 2016-12-10 13:49 -0800

Page 1 of 9  [1] 2 3 4 5 6 7 8 9  Next page →


#98254 — while loop vs do while loop reading from the file issue

FromAlla _ <modelling.data@gmail.com>
Date2016-12-07 05:08 -0800
Subjectwhile loop vs do while loop reading from the file issue
Message-ID<52f1c174-6af1-4fda-9ff8-a5e2cf507b5f@googlegroups.com>
Hello!

Please, take a look at the same program but two versions of it. The first version is 
is written by Deitel&Deitel; in the second version I would like to change 
the while loop into a do while one, but is it possible to set a condition of 
the while statement such that the loop ends right before the EOF, i.e. 
to escape printing the last line twice? Please, note that I understand that 
the current version (2) does print the last line twice because the loop ends only
when EOF is true, and that happens on the forth iteration. Is there a reasonably
simple way to avoid double printing of the last line, or do while loop won't work 
in such circumstances? 
Few words about the program:
- to test the original program I have created a csv file that has 3 lines of data;
- the original program correctly prints out three lines and stops at the EOF;
- I would like to achieve the same result using do while loop. 

(1) original program:

// Reading and printing a sequential file
#include <stdio.h>

int main( void )
{
    unsigned int account; 
    char name[ 30 ]; 
    double balance; 
    
    FILE *cfPtr; // cfPtr = clients.csv file pointer
    
    // fopen opens file; exits program if file cannot be opened
    if ( (cfPtr = fopen( "clients.csv", "r" )) == NULL )
    {
        puts( "File could not be opened" );
    } 
    else 
   {
        // read account, name and balance from file
        printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
        fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );

      // while not end of file
        while (!feof( cfPtr ))
        {
          printf( "%-10d%-13s%7.2f\n", account, name, balance );
          fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
        }
    
        fclose( cfPtr ); // fclose closes the file
      } 
    } 

Output:
Account   Name         Balance
190       mary           89.00
34        john             89.00
367       sandra        46.00

(2) my version with the do while loop:


// Reading and printing a sequential file
#include <stdio.h>

int main( void )
{
    unsigned int account; 
    char name[ 30 ]; 
    double balance; 
    
    FILE *cfPtr; 
    
    // fopen opens file; exits program if file cannot be opened
    if ((cfPtr = fopen( "clients.csv", "r" )) == NULL )
    {
        puts( "File could not be opened" );
    } 
    else
    {
        printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
        do
        {
            fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
            printf( "%-10d%-13s%7.2f\n", account, name, balance );
        }
        while (!feof( cfPtr ));

    fclose( cfPtr ); 
    } 
}
Output:

Account   Name         Balance
190       mary           89.00
34        john           89.00
367       sandra         46.00
367       sandra         46.00

Thank you! 

[toc] | [next] | [standalone]


#98255

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-12-07 13:46 +0000
Message-ID<o293pp$p31$1@dont-email.me>
In reply to#98254
On 07/12/16 13:08, Alla _ wrote:
> Hello!
>
> Please, take a look at the same program but two versions of it. The first version is
> is written by Deitel&Deitel; in the second version I would like to change
> the while loop into a do while one, but is it possible to set a condition of
> the while statement such that the loop ends right before the EOF, i.e.
> to escape printing the last line twice? Please, note that I understand that
> the current version (2) does print the last line twice because the loop ends only
> when EOF is true, and that happens on the forth iteration. Is there a reasonably
> simple way to avoid double printing of the last line, or do while loop won't work
> in such circumstances?
> Few words about the program:
> - to test the original program I have created a csv file that has 3 lines of data;

So have I. It looks like this:
$ cat clients.csv
190,mary,89.00
34,john,89.00
367,sandra,46.00

As you can see, this is a perfectly ordinary CSV (comma-separated 
values) file, as you specified.

> - the original program correctly prints out three lines and stops at the EOF;

Does it now? This is the output I got:

Account   Name         Balance
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00

I allowed the program to run for infinite time, just to be sure, and it 
produced almost infinitely many lines of output. Then the heat death of 
the universe caught up with it.

> (2) my version with the do while loop:


Again, I got this:

Account   Name         Balance
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00
190       ,mary,89.00    34.00

I couldn't wait infinitely long this time, but I gave it a good few 
billion years and it was still running well, and always repeating that 
same data line.

How do you feel about /this/ output?

Account	Name	Balance
190	mary	89.00
34	john	89.00
367	sandra	46.00

The program that generated that output is rather longer than either 
yours or D&D's, but it has the saving grace that it works. Also, you 
will note that it doesn't print the last data line twice (let alone 
print the first line infinitely many times).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
   FILE *fp = fopen("clients.csv", "r");
   if(fp != NULL)
   {
     char line[256] = {0};
     int lnum = 0;

     /* headings */
     printf("Account\tName\tBalance\n");

     while(fgets(line, sizeof line, fp) != NULL)
     {
       int ok = 0;
       char *token = NULL;
       char *endptr = NULL;
       unsigned int account = 0;
       char name[30] = "error";
       double balance = 0.0;
       ++lnum;
       token = strtok(line, ",\n");
       if(token != NULL)
       {
         account = strtoul(token, &endptr, 10);
         if(endptr > token)
         {
           token = strtok(NULL, ",\n");
           if(token != NULL)
           {
             if(strlen(token) < sizeof name)
             {
               strcpy(name, token);
               token = strtok(NULL, ",\n");
               if(token != NULL)
               {
                 balance = strtod(token, &endptr);
                 if(endptr > token)
                 {
                   ok = 1;
                 }
                 else
                 {
                   fprintf(stderr,
                           "Data error: invalid balance"
                           " on line %d.\n",
                           lnum);
                 }
               }
               else
               {
                 fprintf(stderr,
                         "Data error: missing balance"
                         " on line %d.\n",
                         lnum);
               }
             }
             else
             {
               fprintf(stderr,
                       "Security violation: name too"
                       " long on line %d.\n",
                       lnum);
             }
           }
           else
           {
             fprintf(stderr,
                     "Data error: missing name"
                     " on line %d.\n",
                     lnum);
           }
         }
         else
         {
           fprintf(stderr,
                   "Data error: invalid account number"
                   " on line %d.\n",
                   lnum);
         }
       }
       else
       {
         fprintf(stderr,
                 "Data error: unknown data format"
                 " on line %d.\n", lnum);
       }
       if(ok)
       {
         printf("%u\t%s\t%.2f\n", account, name, balance);
       }
     }
     fclose(fp);
   }
   else
   {
     fputs("File could not be opened.\n", stderr);
   }
   return 0;
}




-- 
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

[toc] | [prev] | [next] | [standalone]


#98265

FromAlla _ <modelling.data@gmail.com>
Date2016-12-07 07:27 -0800
Message-ID<804c5bcd-ed62-402c-a8d2-ca67984d8e23@googlegroups.com>
In reply to#98255
On Wednesday, December 7, 2016 at 4:47:02 PM UTC+3, Richard Heathfield wrote:
> On 07/12/16 13:08, Alla _ wrote:
> > Hello!
> >
> > Please, take a look at the same program but two versions of it. The first version is
> > is written by Deitel&Deitel; in the second version I would like to change
> > the while loop into a do while one, but is it possible to set a condition of
> > the while statement such that the loop ends right before the EOF, i.e.
> > to escape printing the last line twice? Please, note that I understand that
> > the current version (2) does print the last line twice because the loop ends only
> > when EOF is true, and that happens on the forth iteration. Is there a reasonably
> > simple way to avoid double printing of the last line, or do while loop won't work
> > in such circumstances?
> > Few words about the program:
> > - to test the original program I have created a csv file that has 3 lines of data;
> 
> So have I. It looks like this:
> $ cat clients.csv
> 190,mary,89.00
> 34,john,89.00
> 367,sandra,46.00
> 
> As you can see, this is a perfectly ordinary CSV (comma-separated 
> values) file, as you specified.
> 
> > - the original program correctly prints out three lines and stops at the EOF;
> 
> Does it now? This is the output I got:
> 
> Account   Name         Balance
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 
> I allowed the program to run for infinite time, just to be sure, and it 
> produced almost infinitely many lines of output. Then the heat death of 
> the universe caught up with it.
> 
The program I copied from D&D prints the correct amount of data from csv file.
Do you imply that this program doesn't perform numerous error checks? Yes,
it doesn't because it's a relatively simple one, in which the authors, I assume, 
merely show the way file i/o works.

> > (2) my version with the do while loop:
> 
> 
> Again, I got this:
> 
> Account   Name         Balance
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 190       ,mary,89.00    34.00
> 
> I couldn't wait infinitely long this time, but I gave it a good few 
> billion years and it was still running well, and always repeating that 
> same data line.
> 
Why do these two versions perform like that in your machine? I don't 
understand it. 

> How do you feel about /this/ output?
> 
> Account	Name	Balance
> 190	mary	89.00
> 34	john	89.00
> 367	sandra	46.00
> 
> The program that generated that output is rather longer than either 
> yours or D&D's, but it has the saving grace that it works. Also, you 
> will note that it doesn't print the last data line twice (let alone 
> print the first line infinitely many times).
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> 
> int main(void)
> {
>    FILE *fp = fopen("clients.csv", "r");
>    if(fp != NULL)
>    {
>      char line[256] = {0};
>      int lnum = 0;
> 
>      /* headings */
>      printf("Account\tName\tBalance\n");
> 
>      while(fgets(line, sizeof line, fp) != NULL)
>      {
>        int ok = 0;
>        char *token = NULL;
>        char *endptr = NULL;
>        unsigned int account = 0;
>        char name[30] = "error";
>        double balance = 0.0;
>        ++lnum;
>        token = strtok(line, ",\n");
>        if(token != NULL)
>        {
>          account = strtoul(token, &endptr, 10);
>          if(endptr > token)
>          {
>            token = strtok(NULL, ",\n");
>            if(token != NULL)
>            {
>              if(strlen(token) < sizeof name)
>              {
>                strcpy(name, token);
>                token = strtok(NULL, ",\n");
>                if(token != NULL)
>                {
>                  balance = strtod(token, &endptr);
>                  if(endptr > token)
>                  {
>                    ok = 1;
>                  }
>                  else
>                  {
>                    fprintf(stderr,
>                            "Data error: invalid balance"
>                            " on line %d.\n",
>                            lnum);
>                  }
>                }
>                else
>                {
>                  fprintf(stderr,
>                          "Data error: missing balance"
>                          " on line %d.\n",
>                          lnum);
>                }
>              }
>              else
>              {
>                fprintf(stderr,
>                        "Security violation: name too"
>                        " long on line %d.\n",
>                        lnum);
>              }
>            }
>            else
>            {
>              fprintf(stderr,
>                      "Data error: missing name"
>                      " on line %d.\n",
>                      lnum);
>            }
>          }
>          else
>          {
>            fprintf(stderr,
>                    "Data error: invalid account number"
>                    " on line %d.\n",
>                    lnum);
>          }
>        }
>        else
>        {
>          fprintf(stderr,
>                  "Data error: unknown data format"
>                  " on line %d.\n", lnum);
>        }
>        if(ok)
>        {
>          printf("%u\t%s\t%.2f\n", account, name, balance);
>        }
>      }
>      fclose(fp);
>    }
>    else
>    {
>      fputs("File could not be opened.\n", stderr);
>    }
>    return 0;
> }
> 

Oh ))))) I wonder if I ever be able to come up with this amount of statements in no time as you
always do )))
> 
> 
> 
> -- 
> 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

[toc] | [prev] | [next] | [standalone]


#98270

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-12-07 16:17 +0000
Message-ID<o29cjv$os4$1@dont-email.me>
In reply to#98265
On 07/12/16 15:27, Alla _ wrote:
> On Wednesday, December 7, 2016 at 4:47:02 PM UTC+3, Richard Heathfield wrote:
>> On 07/12/16 13:08, Alla _ wrote:
>>> Hello!
>>>
>>> Please, take a look at the same program but two versions of it. The first version is
>>> is written by Deitel&Deitel; in the second version I would like to change
>>> the while loop into a do while one, but is it possible to set a condition of
>>> the while statement such that the loop ends right before the EOF, i.e.
>>> to escape printing the last line twice? Please, note that I understand that
>>> the current version (2) does print the last line twice because the loop ends only
>>> when EOF is true, and that happens on the forth iteration. Is there a reasonably
>>> simple way to avoid double printing of the last line, or do while loop won't work
>>> in such circumstances?
>>> Few words about the program:
>>> - to test the original program I have created a csv file that has 3 lines of data;
>>
>> So have I. It looks like this:
>> $ cat clients.csv
>> 190,mary,89.00
>> 34,john,89.00
>> 367,sandra,46.00
>>
>> As you can see, this is a perfectly ordinary CSV (comma-separated
>> values) file, as you specified.
>>
>>> - the original program correctly prints out three lines and stops at the EOF;
>>
>> Does it now? This is the output I got:
>>
>> Account   Name         Balance
>> 190       ,mary,89.00    34.00
>> 190       ,mary,89.00    34.00
>> 190       ,mary,89.00    34.00
>> 190       ,mary,89.00    34.00
>> 190       ,mary,89.00    34.00
>> 190       ,mary,89.00    34.00
>> 190       ,mary,89.00    34.00
>>
>> I allowed the program to run for infinite time, just to be sure, and it
>> produced almost infinitely many lines of output. Then the heat death of
>> the universe caught up with it.
>>
> The program I copied from D&D prints the correct amount of data from csv file.

No, it clearly doesn't.

> Do you imply that this program doesn't perform numerous error checks?

No, I'm saying the program simply does not do what you say it does.

The most likely explanation is that the input file is *not* a CSV file 
after all. Since you didn't show your input file, though, I had to 
reconstruct it from what you had told me: that it was a CSV 
(comma-separated values) file, and that it had the data you had shown.

<snip>

> Oh ))))) I wonder if I ever be able to come up with this amount of statements in no time as you
> always do )))

Festina LENTE!

-- 
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

[toc] | [prev] | [next] | [standalone]


#98257

FromNorbert_Paul <norbertpauls_spambin@yahoo.com>
Date2016-12-07 14:54 +0100
Message-ID<o29479$qcs$1@dont-email.me>
In reply to#98254
Actually, I guess you are kidding --- but nevertheless.

So you have managed to figure out that in your case a while loop is more adequate
and a do-while loop. However, you still "would like to change" it for the less
adequate tool?

Then note that

   if (condition) do { Stuff } while(condition);

is equivalent to

   while (condition) { Stuff }

. (At least for your appplication. Maybe going into all subtle depths of C there
may be some inequivalence I don't notice yet.) So this may be a way to add the
"liked" 'do' keyword (and also more verbosity) if you must do so.


Alla _ wrote:
> Hello!
>
> Please, take a look at the same program but two versions of it. The first version is
> is written by Deitel&Deitel; in the second version I would like to change
> the while loop into a do while one, but is it possible to set a condition of
> the while statement such that the loop ends right before the EOF, i.e.
> to escape printing the last line twice? Please, note that I understand that
> the current version (2) does print the last line twice because the loop ends only
> when EOF is true, and that happens on the forth iteration. Is there a reasonably
> simple way to avoid double printing of the last line, or do while loop won't work
> in such circumstances?
> Few words about the program:
> - to test the original program I have created a csv file that has 3 lines of data;
> - the original program correctly prints out three lines and stops at the EOF;
> - I would like to achieve the same result using do while loop.
>
> (1) original program:
>
> // Reading and printing a sequential file
> #include<stdio.h>
>
> int main( void )
> {
>      unsigned int account;
>      char name[ 30 ];
>      double balance;
>
>      FILE *cfPtr; // cfPtr = clients.csv file pointer
>
>      // fopen opens file; exits program if file cannot be opened
>      if ( (cfPtr = fopen( "clients.csv", "r" )) == NULL )
>      {
>          puts( "File could not be opened" );
>      }
>      else
>     {
>          // read account, name and balance from file
>          printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
>          fscanf( cfPtr, "%d%29s%lf",&account, name,&balance );
>
>        // while not end of file
>          while (!feof( cfPtr ))
>          {
>            printf( "%-10d%-13s%7.2f\n", account, name, balance );
>            fscanf( cfPtr, "%d%29s%lf",&account, name,&balance );
>          }
>
>          fclose( cfPtr ); // fclose closes the file
>        }
>      }
>
> Output:
> Account   Name         Balance
> 190       mary           89.00
> 34        john             89.00
> 367       sandra        46.00
>
> (2) my version with the do while loop:
>
>
> // Reading and printing a sequential file
> #include<stdio.h>
>
> int main( void )
> {
>      unsigned int account;
>      char name[ 30 ];
>      double balance;
>
>      FILE *cfPtr;
>
>      // fopen opens file; exits program if file cannot be opened
>      if ((cfPtr = fopen( "clients.csv", "r" )) == NULL )
>      {
>          puts( "File could not be opened" );
>      }
>      else
>      {
>          printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
>          do
>          {
>              fscanf( cfPtr, "%d%29s%lf",&account, name,&balance );
>              printf( "%-10d%-13s%7.2f\n", account, name, balance );
>          }
>          while (!feof( cfPtr ));
>
>      fclose( cfPtr );
>      }
> }
> Output:
>
> Account   Name         Balance
> 190       mary           89.00
> 34        john           89.00
> 367       sandra         46.00
> 367       sandra         46.00
>
> Thank you!

[toc] | [prev] | [next] | [standalone]


#98266

FromAlla _ <modelling.data@gmail.com>
Date2016-12-07 07:29 -0800
Message-ID<06ec129f-f971-4b12-957a-e1172105b6ca@googlegroups.com>
In reply to#98257
On Wednesday, December 7, 2016 at 4:54:13 PM UTC+3, Norbert_Paul wrote:
> Actually, I guess you are kidding --- but nevertheless.

No, no, I am not - I am merely learning and testing my assumptions, and 
only explanations I get here help me to understand my mistakes, learn more
things, etc. 
> 
> So you have managed to figure out that in your case a while loop is more adequate
> and a do-while loop. However, you still "would like to change" it for the less
> adequate tool?
> 
> Then note that
> 
>    if (condition) do { Stuff } while(condition);
> 
> is equivalent to
> 
>    while (condition) { Stuff }
> 
> . (At least for your appplication. Maybe going into all subtle depths of C there
> may be some inequivalence I don't notice yet.) So this may be a way to add the
> "liked" 'do' keyword (and also more verbosity) if you must do so.
> 
> 
> Alla _ wrote:
> > Hello!
> >
> > Please, take a look at the same program but two versions of it. The first version is
> > is written by Deitel&Deitel; in the second version I would like to change
> > the while loop into a do while one, but is it possible to set a condition of
> > the while statement such that the loop ends right before the EOF, i.e.
> > to escape printing the last line twice? Please, note that I understand that
> > the current version (2) does print the last line twice because the loop ends only
> > when EOF is true, and that happens on the forth iteration. Is there a reasonably
> > simple way to avoid double printing of the last line, or do while loop won't work
> > in such circumstances?
> > Few words about the program:
> > - to test the original program I have created a csv file that has 3 lines of data;
> > - the original program correctly prints out three lines and stops at the EOF;
> > - I would like to achieve the same result using do while loop.
> >
> > (1) original program:
> >
> > // Reading and printing a sequential file
> > #include<stdio.h>
> >
> > int main( void )
> > {
> >      unsigned int account;
> >      char name[ 30 ];
> >      double balance;
> >
> >      FILE *cfPtr; // cfPtr = clients.csv file pointer
> >
> >      // fopen opens file; exits program if file cannot be opened
> >      if ( (cfPtr = fopen( "clients.csv", "r" )) == NULL )
> >      {
> >          puts( "File could not be opened" );
> >      }
> >      else
> >     {
> >          // read account, name and balance from file
> >          printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
> >          fscanf( cfPtr, "%d%29s%lf",&account, name,&balance );
> >
> >        // while not end of file
> >          while (!feof( cfPtr ))
> >          {
> >            printf( "%-10d%-13s%7.2f\n", account, name, balance );
> >            fscanf( cfPtr, "%d%29s%lf",&account, name,&balance );
> >          }
> >
> >          fclose( cfPtr ); // fclose closes the file
> >        }
> >      }
> >
> > Output:
> > Account   Name         Balance
> > 190       mary           89.00
> > 34        john             89.00
> > 367       sandra        46.00
> >
> > (2) my version with the do while loop:
> >
> >
> > // Reading and printing a sequential file
> > #include<stdio.h>
> >
> > int main( void )
> > {
> >      unsigned int account;
> >      char name[ 30 ];
> >      double balance;
> >
> >      FILE *cfPtr;
> >
> >      // fopen opens file; exits program if file cannot be opened
> >      if ((cfPtr = fopen( "clients.csv", "r" )) == NULL )
> >      {
> >          puts( "File could not be opened" );
> >      }
> >      else
> >      {
> >          printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
> >          do
> >          {
> >              fscanf( cfPtr, "%d%29s%lf",&account, name,&balance );
> >              printf( "%-10d%-13s%7.2f\n", account, name, balance );
> >          }
> >          while (!feof( cfPtr ));
> >
> >      fclose( cfPtr );
> >      }
> > }
> > Output:
> >
> > Account   Name         Balance
> > 190       mary           89.00
> > 34        john           89.00
> > 367       sandra         46.00
> > 367       sandra         46.00
> >
> > Thank you!

[toc] | [prev] | [next] | [standalone]


#98273

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-12-07 17:20 +0000
Message-ID<87twafejw4.fsf@bsb.me.uk>
In reply to#98254
Alla _ <modelling.data@gmail.com> writes:

> Please, take a look at the same program but two versions of it. The
> first version is is written by Deitel&Deitel; in the second version I
> would like to change the while loop into a do while one,

Why?

>         // read account, name and balance from file
>         printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
>         fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
>
>       // while not end of file
>         while (!feof( cfPtr ))
>         {
>           printf( "%-10d%-13s%7.2f\n", account, name, balance );
>           fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
>         }

You say elsewhere that the code is written like this to be simple, but a
version that does the right sort of error checking is simpler:

  while (fscanf( cfPtr, "%d%29s%lf", &account, name, &balance ) == 3)
      printf( "%-10d%-13s%7.2f\n", account, name, balance );

Two lines (four if you want to add the noisy {}s) rather than 5 (or 7).

Always check input operations for success not failure.  If fscanf
returns 3 you got three items and can go ahead.  EOF is only one reason
that the input can fail and it's not worth trying to think of them all.

You can use feof and ferror and so on (and maybe save and use the value
returned by fscanf) if you must report some detailed explanation of the
problem, but start by only printing data you know you got.

When you see

   input;
   while (C) {
     S;
     input;
   }

you should immediately think of trying

  while (input) S;

though you do sometimes need the condition to be preserved:

  while (input && C) S;

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#98275

From"Mr. Man-wai Chang" <toylet.toylet@gmail.com>
Date2016-12-08 01:24 +0800
Message-ID<o29gi6$781$1@dont-email.me>
In reply to#98273
In dBsae and Clipper, it's usually:

select dbf_alias
go top
do while .not. eof()
    read_and_process_record()
    select dbf_alias
    skip
enddo

On 8/12/2016 1:20 AM, Ben Bacarisse wrote:
>    input;
>    while (C) {
>      S;
>      input;
>    }
>
> you should immediately think of trying
>
>   while (input) S;
>
> though you do sometimes need the condition to be preserved:
>
>   while (input && C) S;
>
> <snip>
>

[toc] | [prev] | [next] | [standalone]


#98339

FromAlla _ <modelling.data@gmail.com>
Date2016-12-07 22:51 -0800
Message-ID<33f30ec0-c261-4cc2-8bef-54e652332243@googlegroups.com>
In reply to#98273
On Wednesday, December 7, 2016 at 8:20:27 PM UTC+3, Ben Bacarisse wrote:
> Alla _ <modelling.data@gmail.com> writes:
> 
> > Please, take a look at the same program but two versions of it. The
> > first version is is written by Deitel&Deitel; in the second version I
> > would like to change the while loop into a do while one,
> 
> Why?
I thought that it might work also; simply testing myself.
Though not the best idea this time, as I see now. 
> 
> >         // read account, name and balance from file
> >         printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
> >         fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
> >
> >       // while not end of file
> >         while (!feof( cfPtr ))
> >         {
> >           printf( "%-10d%-13s%7.2f\n", account, name, balance );
> >           fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
> >         }
> 
> You say elsewhere that the code is written like this to be simple, but a
> version that does the right sort of error checking is simpler:
> 
>   while (fscanf( cfPtr, "%d%29s%lf", &account, name, &balance ) == 3)
>       printf( "%-10d%-13s%7.2f\n", account, name, balance );
> 
> Two lines (four if you want to add the noisy {}s) rather than 5 (or 7).
> 
> Always check input operations for success not failure.  If fscanf
> returns 3 you got three items and can go ahead.  EOF is only one reason
> that the input can fail and it's not worth trying to think of them all.
> 
I see. Thank you very much. 

> You can use feof and ferror and so on (and maybe save and use the value
> returned by fscanf) if you must report some detailed explanation of the
> problem, but start by only printing data you know you got.
> 
> When you see
> 
>    input;
>    while (C) {
>      S;
>      input;
>    }
> 
> you should immediately think of trying
> 
>   while (input) S;
> 
> though you do sometimes need the condition to be preserved:
> 
>   while (input && C) S;
> 
Yes, it worried me that the "input" has been used twice, before and within the loop.
I see now how to avoid this. Thank you!
> <snip>
> -- 
> Ben.

[toc] | [prev] | [next] | [standalone]


#98343

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-12-08 07:30 +0000
Message-ID<o2b23h$n0f$1@dont-email.me>
In reply to#98339
On 08/12/16 06:51, Alla _ wrote:
> On Wednesday, December 7, 2016 at 8:20:27 PM UTC+3, Ben Bacarisse wrote:
<snip>
>>
>> When you see
>>
>>    input;
>>    while (C) {
>>      S;
>>      input;
>>    }
>>
>> you should immediately think of trying
>>
>>   while (input) S;
>>
>> though you do sometimes need the condition to be preserved:
>>
>>   while (input && C) S;
>>
> Yes, it worried me that the "input" has been used twice, before and within the loop.
> I see now how to avoid this.

You see /now/? Didn't I show you how to do that *yesterday*? Why has it 
taken until now to see it?

-- 
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

[toc] | [prev] | [next] | [standalone]


#98277

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2016-12-07 12:45 -0500
Message-ID<o29hq3$c7p$1@dont-email.me>
In reply to#98254
On Wednesday December 7 2016 08:08, in comp.lang.c, "Alla _"
<modelling.data@gmail.com> wrote:

> Hello!
> 
> Please, take a look at the same program but two versions of it. The first
> version is is written by Deitel&Deitel; in the second version I would like
> to change the while loop into a do while one, but is it possible to set a
> condition of the while statement such that the loop ends right before the
> EOF, i.e. to escape printing the last line twice? 
[snip]
> (2) my version with the do while loop:
> 

I make no comments on the correctness of this code other than on the specific
use of feof(). I know that this code doesn't do what you claim it does, and I
know /why/ it doesn't work.

> // Reading and printing a sequential file
> #include <stdio.h>
> 
> int main( void )
> {
>     unsigned int account;
>     char name[ 30 ];
>     double balance;
>     
>     FILE *cfPtr;
>     
>     // fopen opens file; exits program if file cannot be opened
>     if ((cfPtr = fopen( "clients.csv", "r" )) == NULL )
>     {
>         puts( "File could not be opened" );
>     }
>     else
>     {
>         printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
>         do
>         {
>             fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
>             printf( "%-10d%-13s%7.2f\n", account, name, balance );
>         }
>         while (!feof( cfPtr ));

"The feof function tests the end-of-file indicator for the stream pointed to by
stream." (so says the C standard). The end-of-file indicator is set when a
file read function (like fgets(), fscanf(), etc) can no longer read data from
the file. In other words, the end-of-file indicator is set AFTER the read
determines that there is no more data.

Assume that you have successfully processed almost all the lines in your input
file, and are about to process the last line.

At the top of your do-while:
 -  fscanf() pulls in the remaining line and populates account, name and
    balance. it does /not/ set the end-of-file indicator.
 -  printf() prints the values in account, name, and balance
 -  feof(cfPtr) returns 0 because we have not yet reached end-of-file
    and the do-while starts again.
 -  fscanf() encounters the end of the file, and sets the end-of-file
    indicator
 -  printf prints the values in account, name and balance
 -  feof(cfPtr) returns 1 because the end-of-file indicator is now set,
    and the loop terminates.

See the problem? You print the last line twice because your logic does not
test for end-of-file at a point to avoid printing the leftovers from the
previous loop.

>     fclose( cfPtr );
>     }
> }
> Output:
> 
> Account   Name         Balance
> 190       mary           89.00
> 34        john           89.00
> 367       sandra         46.00
> 367       sandra         46.00
> 
> Thank you!

Like Richard, I get an infinite loop of ill-formed data.

You need to review how fscanf() determines where each input field starts and
ends, and what it (fscanf) does when it cannot find a specified field.


-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#98278

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-12-07 17:50 +0000
Message-ID<o29i1r$cfv$1@dont-email.me>
In reply to#98277
On 07/12/16 17:45, Lew Pitcher wrote:

<snip>

> Like Richard, I get an infinite loop of ill-formed data.

This is almost certainly because the code was not, despite Alla's claim, 
written to handle CSV files. There is no CSV-parsing logic whatsoever in 
either her program or the original.

> You need to review how fscanf() determines where each input field starts and
> ends, and what it (fscanf) does when it cannot find a specified field.

Yes, and she also needs to learn what is meant by "CSV".

-- 
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

[toc] | [prev] | [next] | [standalone]


#98280

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2016-12-07 12:56 -0500
Message-ID<o29id9$egc$1@dont-email.me>
In reply to#98278
On Wednesday December 7 2016 12:50, in comp.lang.c, "Richard Heathfield"
<rjh@cpax.org.uk> wrote:

> On 07/12/16 17:45, Lew Pitcher wrote:
> 
> <snip>
> 
>> Like Richard, I get an infinite loop of ill-formed data.
> 
> This is almost certainly because the code was not, despite Alla's claim,
> written to handle CSV files. There is no CSV-parsing logic whatsoever in
> either her program or the original.
> 
>> You need to review how fscanf() determines where each input field starts
>> and ends, and what it (fscanf) does when it cannot find a specified field.
> 
> Yes, and she also needs to learn what is meant by "CSV".

Yes, indeed. But even that isn't enough.
Question: With fscanf(), what character sequence delimits the end of a string?



-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#98283

FromBarry Schwarz <schwarzb@dqel.com>
Date2016-12-07 11:09 -0800
Message-ID<ihng4clp2cjofv1ggvdfu0oqqiglsu9u6f@4ax.com>
In reply to#98280
On Wed, 07 Dec 2016 12:56:08 -0500, Lew Pitcher
<lew.pitcher@digitalfreehold.ca> wrote:

>On Wednesday December 7 2016 12:50, in comp.lang.c, "Richard Heathfield"
><rjh@cpax.org.uk> wrote:
>
>> On 07/12/16 17:45, Lew Pitcher wrote:
>> 
>> <snip>
>> 
>>> Like Richard, I get an infinite loop of ill-formed data.
>> 
>> This is almost certainly because the code was not, despite Alla's claim,
>> written to handle CSV files. There is no CSV-parsing logic whatsoever in
>> either her program or the original.
>> 
>>> You need to review how fscanf() determines where each input field starts
>>> and ends, and what it (fscanf) does when it cannot find a specified field.
>> 
>> Yes, and she also needs to learn what is meant by "CSV".
>
>Yes, indeed. But even that isn't enough.
>Question: With fscanf(), what character sequence delimits the end of a string?

A white space character (or exhausting the count if specified).

-- 
Remove del for email

[toc] | [prev] | [next] | [standalone]


#98286

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2016-12-07 14:38 -0500
Message-ID<o29ocj$519$1@dont-email.me>
In reply to#98283
On Wednesday December 7 2016 14:09, in comp.lang.c, "Barry Schwarz"
<schwarzb@dqel.com> wrote:

> On Wed, 07 Dec 2016 12:56:08 -0500, Lew Pitcher
> <lew.pitcher@digitalfreehold.ca> wrote:
> 
>>On Wednesday December 7 2016 12:50, in comp.lang.c, "Richard Heathfield"
>><rjh@cpax.org.uk> wrote:
>>
>>> On 07/12/16 17:45, Lew Pitcher wrote:
>>> 
>>> <snip>
>>> 
>>>> Like Richard, I get an infinite loop of ill-formed data.
>>> 
>>> This is almost certainly because the code was not, despite Alla's claim,
>>> written to handle CSV files. There is no CSV-parsing logic whatsoever in
>>> either her program or the original.
>>> 
>>>> You need to review how fscanf() determines where each input field starts
>>>> and ends, and what it (fscanf) does when it cannot find a specified
>>>> field.
>>> 
>>> Yes, and she also needs to learn what is meant by "CSV".
>>
>>Yes, indeed. But even that isn't enough.
>>Question: With fscanf(), what character sequence delimits the end of a
>>string?
> 
> A white space character (or exhausting the count if specified).

That was a rhetorical question, for Alla's benefit. 

Let's note that "white space" includes
  ' '  (space),
  '\f' (formfeed),
  '\n' (newline - that character (sequence) that separates lines
        in a text file),
  '\r' (carriage return),
  '\t' (horizontal tab), and
  '\v' (vertical tab)

Alla, do you see a problem with your fscanf() parsing of the name field?


-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#98342

FromAlla _ <modelling.data@gmail.com>
Date2016-12-07 23:29 -0800
Message-ID<5d94897b-fedc-4a28-81d0-3579e9bf754d@googlegroups.com>
In reply to#98286
On Wednesday, December 7, 2016 at 10:38:21 PM UTC+3, Lew Pitcher wrote:
> On Wednesday December 7 2016 14:09, in comp.lang.c, "Barry Schwarz"
> <schwarzb@dqel.com> wrote:
> 
> > On Wed, 07 Dec 2016 12:56:08 -0500, Lew Pitcher
> > <lew.pitcher@digitalfreehold.ca> wrote:
> > 
> >>On Wednesday December 7 2016 12:50, in comp.lang.c, "Richard Heathfield"
> >><rjh@cpax.org.uk> wrote:
> >>
> >>> On 07/12/16 17:45, Lew Pitcher wrote:
> >>> 
> >>> <snip>
> >>> 
> >>>> Like Richard, I get an infinite loop of ill-formed data.
> >>> 
> >>> This is almost certainly because the code was not, despite Alla's claim,
> >>> written to handle CSV files. There is no CSV-parsing logic whatsoever in
> >>> either her program or the original.
> >>> 
> >>>> You need to review how fscanf() determines where each input field starts
> >>>> and ends, and what it (fscanf) does when it cannot find a specified
> >>>> field.
> >>> 
> >>> Yes, and she also needs to learn what is meant by "CSV".
> >>
> >>Yes, indeed. But even that isn't enough.
> >>Question: With fscanf(), what character sequence delimits the end of a
> >>string?
> > 
> > A white space character (or exhausting the count if specified).
> 
> That was a rhetorical question, for Alla's benefit. 
> 
> Let's note that "white space" includes
>   ' '  (space),
>   '\f' (formfeed),
>   '\n' (newline - that character (sequence) that separates lines
>         in a text file),
>   '\r' (carriage return),
>   '\t' (horizontal tab), and
>   '\v' (vertical tab)
> 
> Alla, do you see a problem with your fscanf() parsing of the name field?

I am sorry for asking this: what exactly does "name field" mean in this context;
does it mean account, name, and balance? 
 fscanf( cfPtr, "%d%29s%lf", &account, name, &balance ); 

You have asked a very important question, and I have to clear up this issue, because
in a program I am preparing I have to write data from the excel file; and I wonder
if I need to convert that file into csv format first to be able to extract the data. 
Please, do not address this issue for now, because it will start a completely new discussion,
which requires a separate thread. Now it is important for me to make sure I understand
and know what you are referring to in your question. 
> 
> 
> -- 
> Lew Pitcher
> "In Skills, We Trust"
> PGP public key available upon request

[toc] | [prev] | [next] | [standalone]


#98345

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-12-08 07:35 +0000
Message-ID<o2b2dn$on2$1@dont-email.me>
In reply to#98342
On 08/12/16 07:29, Alla _ wrote:
> On Wednesday, December 7, 2016 at 10:38:21 PM UTC+3, Lew Pitcher wrote:
>> On Wednesday December 7 2016 14:09, in comp.lang.c, "Barry Schwarz"
>> <schwarzb@dqel.com> wrote:
>>
>>> On Wed, 07 Dec 2016 12:56:08 -0500, Lew Pitcher
>>> <lew.pitcher@digitalfreehold.ca> wrote:
>>>
>>>> On Wednesday December 7 2016 12:50, in comp.lang.c, "Richard Heathfield"
>>>> <rjh@cpax.org.uk> wrote:
>>>>
>>>>> On 07/12/16 17:45, Lew Pitcher wrote:
>>>>>
>>>>> <snip>
>>>>>
>>>>>> Like Richard, I get an infinite loop of ill-formed data.
>>>>>
>>>>> This is almost certainly because the code was not, despite Alla's claim,
>>>>> written to handle CSV files. There is no CSV-parsing logic whatsoever in
>>>>> either her program or the original.
>>>>>
>>>>>> You need to review how fscanf() determines where each input field starts
>>>>>> and ends, and what it (fscanf) does when it cannot find a specified
>>>>>> field.
>>>>>
>>>>> Yes, and she also needs to learn what is meant by "CSV".
>>>>
>>>> Yes, indeed. But even that isn't enough.
>>>> Question: With fscanf(), what character sequence delimits the end of a
>>>> string?
>>>
>>> A white space character (or exhausting the count if specified).
>>
>> That was a rhetorical question, for Alla's benefit.
>>
>> Let's note that "white space" includes
>>   ' '  (space),
>>   '\f' (formfeed),
>>   '\n' (newline - that character (sequence) that separates lines
>>         in a text file),
>>   '\r' (carriage return),
>>   '\t' (horizontal tab), and
>>   '\v' (vertical tab)
>>
>> Alla, do you see a problem with your fscanf() parsing of the name field?
>
> I am sorry for asking this: what exactly does "name field" mean in this context;
> does it mean account, name, and balance?
>  fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );

He means the data that you are asking fscanf to recognise by %29s and 
store in the array of char that you called 'name', as in char name[30].

> You have asked a very important question, and I have to clear up this issue, because
> in a program I am preparing I have to write data from the excel file; and I wonder
> if I need to convert that file into csv format first to be able to extract the data.

Well, you /said/ it was /already/ in csv format, so why would you need 
to convert it? But if it's already in csv format, why doesn't your 
program cope with csv files, and why do you obviously think it /does/ 
cope with them?

More 'why' questions, I see. Sorry about that.

-- 
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

[toc] | [prev] | [next] | [standalone]


#98377

FromManfred <noname@invalid.add>
Date2016-12-08 16:57 +0100
Message-ID<o2bvsg$np1$1@gioia.aioe.org>
In reply to#98345
On 12/8/2016 8:35 AM, Richard Heathfield wrote:
> On 08/12/16 07:29, Alla _ wrote:
>> On Wednesday, December 7, 2016 at 10:38:21 PM UTC+3, Lew Pitcher wrote:
>>> Alla, do you see a problem with your fscanf() parsing of the name field?
>>
>> I am sorry for asking this: what exactly does "name field" mean in
>> this context;
>> does it mean account, name, and balance?
>>  fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
>
> He means the data that you are asking fscanf to recognise by %29s and
> store in the array of char that you called 'name', as in char name[30].

I may put this in other words, hoping to clarify a bit (and not making 
it more confused)
The term 'field' is often used e.g. with databases and spreadsheets, 
where a data table consists of a sequence of records, each of which is 
divided into a series of fields (and all records share the same field 
structure).
A text-file based representation can be that each record is a line in 
the file, and each line is divided into a number of fields.
In this structure, fields may be separated in various ways - by 
conventionally assigning a fixed number of characters, or by using 
special 'separator' characters, or whatever.
In your case you are dealing with separators: the CSV format uses commas 
as separators (hence the name).
But your fscanf call (also in the D&D implementation)  does not handle 
commas as separators.
 From what I can see the code is not meant to handle CSV files, it 
assumes that the input fields are space separated.

In this kind of problems it is essential that the input file format be 
very accurately specified, otherwise it is most likely impossible to 
code any implementation and expect it to work well.
So, it looks like you need to make clear what is the input format for 
your problem, and only after that you can decide about while or do while.

>
>> You have asked a very important question, and I have to clear up this
>> issue, because
>> in a program I am preparing I have to write data from the excel file;
>> and I wonder
"write data from" - well, I guess either "write data /to/" or "/read/ 
data from"

>> if I need to convert that file into csv format first to be able to
>> extract the data.
>
> Well, you /said/ it was /already/ in csv format, so why would you need
> to convert it? But if it's already in csv format, why doesn't your
> program cope with csv files, and why do you obviously think it /does/
> cope with them?
>
> More 'why' questions, I see. Sorry about that.
>

[toc] | [prev] | [next] | [standalone]


#98678

FromAlla _ <modelling.data@gmail.com>
Date2016-12-10 03:45 -0800
Message-ID<2195e4f6-fa4c-465c-ab10-0d3182074518@googlegroups.com>
In reply to#98377
On Thursday, December 8, 2016 at 6:57:12 PM UTC+3, Manfred wrote:
> On 12/8/2016 8:35 AM, Richard Heathfield wrote:
> > On 08/12/16 07:29, Alla _ wrote:
> >> On Wednesday, December 7, 2016 at 10:38:21 PM UTC+3, Lew Pitcher wrote:
> >>> Alla, do you see a problem with your fscanf() parsing of the name field?
> >>
> >> I am sorry for asking this: what exactly does "name field" mean in
> >> this context;
> >> does it mean account, name, and balance?
> >>  fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
> >
> > He means the data that you are asking fscanf to recognise by %29s and
> > store in the array of char that you called 'name', as in char name[30].
> 
> I may put this in other words, hoping to clarify a bit (and not making 
> it more confused)
> The term 'field' is often used e.g. with databases and spreadsheets, 
> where a data table consists of a sequence of records, each of which is 
> divided into a series of fields (and all records share the same field 
> structure).
> A text-file based representation can be that each record is a line in 
> the file, and each line is divided into a number of fields.
> In this structure, fields may be separated in various ways - by 
> conventionally assigning a fixed number of characters, or by using 
> special 'separator' characters, or whatever.
> In your case you are dealing with separators: the CSV format uses commas 
> as separators (hence the name).
> But your fscanf call (also in the D&D implementation)  does not handle 
> commas as separators.
>  From what I can see the code is not meant to handle CSV files, it 
> assumes that the input fields are space separated.
> 
Thank you for your explanations. Yes, after all these post I know
that I have completely left out essential parts of the code to make
it read/write csv formats. Learning )
> In this kind of problems it is essential that the input file format be 
> very accurately specified, otherwise it is most likely impossible to 
> code any implementation and expect it to work well.
> So, it looks like you need to make clear what is the input format for 
> your problem, and only after that you can decide about while or do while.
> 
> >
> >> You have asked a very important question, and I have to clear up this
> >> issue, because
> >> in a program I am preparing I have to write data from the excel file;
> >> and I wonder
> "write data from" - well, I guess either "write data /to/" or "/read/ 
> data from"
> 
yes, sorry for that )

> >> if I need to convert that file into csv format first to be able to
> >> extract the data.
> >
> > Well, you /said/ it was /already/ in csv format, so why would you need
> > to convert it? But if it's already in csv format, why doesn't your
> > program cope with csv files, and why do you obviously think it /does/
> > cope with them?
> >
> > More 'why' questions, I see. Sorry about that.
> >

[toc] | [prev] | [next] | [standalone]


#98464

FromAlla _ <modelling.data@gmail.com>
Date2016-12-09 01:08 -0800
Message-ID<4d53f1c5-b622-4425-9dfe-694c42676cae@googlegroups.com>
In reply to#98345
On Thursday, December 8, 2016 at 10:35:42 AM UTC+3, Richard Heathfield wrote:
> On 08/12/16 07:29, Alla _ wrote:
> > On Wednesday, December 7, 2016 at 10:38:21 PM UTC+3, Lew Pitcher wrote:
> >> On Wednesday December 7 2016 14:09, in comp.lang.c, "Barry Schwarz"
> >> <schwarzb@dqel.com> wrote:
> >>
> >>> On Wed, 07 Dec 2016 12:56:08 -0500, Lew Pitcher
> >>> <lew.pitcher@digitalfreehold.ca> wrote:
> >>>
> >>>> On Wednesday December 7 2016 12:50, in comp.lang.c, "Richard Heathfield"
> >>>> <rjh@cpax.org.uk> wrote:
> >>>>
> >>>>> On 07/12/16 17:45, Lew Pitcher wrote:
> >>>>>
> >>>>> <snip>
> >>>>>
> >>>>>> Like Richard, I get an infinite loop of ill-formed data.
> >>>>>
> >>>>> This is almost certainly because the code was not, despite Alla's claim,
> >>>>> written to handle CSV files. There is no CSV-parsing logic whatsoever in
> >>>>> either her program or the original.
> >>>>>
<snip>
> Well, you /said/ it was /already/ in csv format, so why would you need 
> to convert it? But if it's already in csv format, why doesn't your 
> program cope with csv files, and why do you obviously think it /does/ 
> cope with them?
> 
> More 'why' questions, I see. Sorry about that.

I am totally fine with 'why's - they are very helpful and provocative;
some sort of a socratic method )
Based on your questions and questions posted by Lew in his helpful answer (below),
I have understood that I did not make myself 100% clear about the versions I posted here. 
I did hope that my initial explanations are suffice. 
To make things clear, and to do so, let's forget about the 'do-while' loop story for now
(it's solved anyway):

1) The program I have posted is from D&D; hence all fscanf, and other functions, and their
formats are not my invention. 
2) This particular program is the second one in the chain of file i/o programs.
3) Therefore the program before it was the one that has created that csv file. See below
under I.
4) The only thing I have changed in the original program is, indeed, the file extension:
I have used .csv, while D&D use .dat.
5) I did manage to get the result I have posted in my original message: the file was created
with the content I showed and then this content has been read successfully (I am again referring
to the note I wrote before this explanation - nothing to do with the do-while topic).
 
Now I wonder does it mean that the file format change has caused the gibberish that 
you get when running the program? I have now tried another program, which has almost
same steps (see below under II) and it indeed writes a nonsensical data into the created csv file. 

Note: the style of commenting is not mine either 

( I ) two original programs: one creates a file, another reads from that file. 

// Fig. 11.2: fig11_02.c
// Creating a sequential file

#include <stdio.h>

int main( void )
{
    unsigned int account; // account number
    char name[ 30 ]; // account name
    double balance; // account balance
    
    FILE *cfPtr; // cfPtr = clients.csv file pointer
    
    // fopen opens file. Exit program if unable to create file
    if ( (cfPtr = fopen( "clients.csv", "w")) == NULL )
    {
        puts( "File could not be opened" );
    } // end if
    else
    {
        puts( "Enter the account, name, and balance." );
        puts( "Enter EOF to end input." );
        printf( "%s", "? " );
        scanf( "%d%29s%lf", &account, name, &balance );
        
        // write account, name and balance into file with fprintf
        while ( !feof( stdin ) )
        {
            fprintf( cfPtr, "%d %s %.2f\n", account, name, balance );
            
            /**
             fprintf( stdout, "%d %s %.2f\n", account, name, balance );
             to print the data to the standard output
             **/
            
            printf( "%s", "? " );
            scanf( "%d%29s%lf", &account, name, &balance );
        } // end while
        
        fclose( cfPtr ); // fclose closes file
        
    } // end else
} // end main

second program:

// Fig. 11.6: fig11_06.c
// Reading and printing a sequential file
#include <stdio.h>

int main( void )
{
    unsigned int account; // account number
    char name[ 30 ]; // account name
    double balance; // account balance
    
    FILE *cfPtr; // cfPtr = clients.csv file pointer
    
    // fopen opens file; exits program if file cannot be opened
    if ( (cfPtr = fopen( "clients.csv", "r" )) == NULL )
    {
        puts( "File could not be opened" );
    } // end if
    else {
        // read account, name and balance from file
        printf( "%-10s%-13s%s\n", "Account", "Name", "Balance" );
        fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );

      // while not end of file
        while (!feof( cfPtr ))
        {
          printf( "%-10d%-13s%7.2f\n", account, name, balance );
          fscanf( cfPtr, "%d%29s%lf", &account, name, &balance );
        } // end while
    
        fclose( cfPtr ); // fclose closes the file
      } // end else
    } // end main

(II) // Fig. 11.10: fig11_10.c2
// Creating a random-access file sequentially
#include <stdio.h>

// clientData structure definition
struct clientData {
    unsigned int acctNum; // account number
    char lastName[ 15 ]; // account last name
    char firstName[ 10 ]; // account first name
    double balance; // account balance
}; // end structure clientData

int main( void )
{
    // counter used to count from 1-100
    unsigned int i;
    
    // create clientData with default information
    struct clientData blankClient = { 0, "", "", 0.0 };
    
    // credit.csv file pointer
    FILE *cfPtr;
    
    // fopen opens the file; exits if file cannot be opened
    if ( ( cfPtr = fopen( "credit.csv", "wb") ) == NULL )
    {
        puts( "File could not be opened." );
    }
    else
    {
        // output 100 blank records to file
        for ( i = 1; i <= 100; ++i )
        {
            fwrite( &blankClient, sizeof( struct clientData ), 1, cfPtr );
        }
        fclose(cfPtr);
    }
}

// Fig. 11.11: fig11_11.c
// Writing data randomly to a random-access file
#include <stdio.h>

// clientData structure definition
struct clientData {
    unsigned int acctNum; // account number
    char lastName[ 15 ]; // account last name
    char firstName[ 10 ]; // account first name
    double balance; // account balance
};

int main( void )
{
    
    FILE *cfPtr; // credit.csv file pointer
    
    // create clientData with default information
    struct clientData client = { 0, "", "", 0.0 };
    
    // fopen opens the file; exits if file cannot be opened
    if ( ( cfPtr = fopen( "credit.csv", "rb+" ) ) == NULL )
    {
        puts( "File could not be opened." );
    }
  else
  {
      // require user to specify account number
      printf( "%s", "Enter account number"
                " ( 1 to 100, 0 to end input )\n? " );
      scanf( "%d", &client.acctNum );
      
      // user enters information, which is copied into file
      while ( client.acctNum != 0 )
      {
          // user enters last name, first name and balance
          printf( "%s", "Enter lastname, firstname, balance\n? " );
          
          // set record lastName, firstName and balance value
          fscanf( stdin, "%14s%9s%lf", client.lastName,
                    client.firstName, &client.balance );
          
          // seek position in file to user-specified record
          fseek( cfPtr, ( client.acctNum - 1 ) *
                sizeof( struct clientData ), SEEK_SET );
          // write user-specified information in file
          fwrite( &client, sizeof( struct clientData ), 1, cfPtr );
          
          // enable user to input another account number
          printf( "%s", "Enter account number\n? " );
          scanf( "%d", &client.acctNum );
      }
      fclose(cfPtr);
  }
}

I ran the second program with the following input:
Enter account number ( 1 to 100, 0 to end input )
? 37
Enter lastname, firstname, balance
? Barker Doug 0.00
Enter account number
? 29
Enter lastname, firstname, balance
? Brown Nancy -24.53
Enter account number
? 0

And the result in csv file is: 
BrownNancyHáz®‡8À%BarkerDoug

[toc] | [prev] | [next] | [standalone]


Page 1 of 9  [1] 2 3 4 5 6 7 8 9  Next page →

Back to top | Article view | comp.lang.c


csiph-web