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


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

Problem with the function that should display new letter

Started byAlla _ <modelling.data@gmail.com>
First post2015-10-27 09:52 -0700
Last post2015-10-31 01:14 -0700
Articles 20 on this page of 174 — 20 participants

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


Contents

  Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 09:52 -0700
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 10:06 -0700
      Re: Problem with the function that should display new letter John Gordon <gordon@panix.com> - 2015-10-27 17:16 +0000
        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 11:28 -0700
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 10:09 -0700
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 10:12 -0700
      Re: Problem with the function that should display new letter Barry Schwarz <schwarzb@dqel.com> - 2015-10-27 13:12 -0700
        Re: Problem with the function that should display new letter supercat@casperkitty.com - 2015-10-27 13:23 -0700
          Re: Problem with the function that should display new letter Keith Thompson <kst-u@mib.org> - 2015-10-27 13:49 -0700
            Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-27 21:27 +0000
              Re: Problem with the function that should display new letter Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-10-27 18:00 -0400
              Re: Problem with the function that should display new letter glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-28 02:53 +0000
                Re: Problem with the function that should display new letter Robert Wessel <robertwessel2@yahoo.com> - 2015-10-28 00:43 -0500
                Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 06:08 +0000
                  Re: Problem with the function that should display new letter glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-28 08:44 +0000
              Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-28 09:26 +0100
                Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 08:44 +0000
                  Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-28 10:40 +0100
                  Re: Problem with the function that should display new letter supercat@casperkitty.com - 2015-10-28 06:44 -0700
                Re: Problem with the function that should display new letter supercat@casperkitty.com - 2015-10-28 06:35 -0700
    Re: Problem with the function that should display new letter "D. Aaron Sawyer" <aaron@110.net> - 2015-10-27 13:40 -0400
      Re: Problem with the function that should display new letter "D. Aaron Sawyer" <aaron@110.net> - 2015-10-27 13:47 -0400
        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 11:38 -0700
          Re: Problem with the function that should display new letter "D. Aaron Sawyer" <aaron@110.net> - 2015-10-27 16:46 -0400
      Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 11:39 -0700
    Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 18:20 +0000
      Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 11:36 -0700
      Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 12:09 -0700
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 11:51 -0700
    Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-27 19:25 +0000
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-27 12:27 -0700
      Re: Problem with the function that should display new letter Ian Collins <ian-news@hotmail.com> - 2015-10-28 10:07 +1300
        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-28 00:50 -0700
          Re: Problem with the function that should display new letter Ian Collins <ian-news@hotmail.com> - 2015-10-28 21:04 +1300
            Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-28 01:13 -0700
            Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 10:40 +0000
              Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 11:02 +0000
              Re: Problem with the function that should display new letter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-28 11:28 +0000
                Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 11:57 +0000
                  Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 12:53 +0000
                  Re: Problem with the function that should display new letter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-28 13:33 +0000
          Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 08:35 +0000
            Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 10:59 +0000
              Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 11:04 +0000
                Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 11:38 +0000
                  Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 11:43 +0000
                    Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 12:10 +0000
                      Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 12:58 +0000
                        Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 13:55 +0000
                          Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 14:02 +0000
                            Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 15:01 +0000
                              Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 15:44 +0000
                                Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 16:22 +0000
                                  Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 16:26 +0000
                                    Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 16:44 +0000
                                      Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 18:45 +0000
                                        Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 19:26 +0000
                                          Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-28 20:44 +0000
                                  Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-28 22:59 +0100
                                    Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 22:48 +0000
                                      Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-29 01:14 +0100
                                        Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-29 01:07 +0000
                                          Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-29 14:07 +0100
                                            Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-29 13:57 +0000
                                              Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-29 16:22 +0100
                                                Re: Problem with the function that should display new letter supercat@casperkitty.com - 2015-10-29 08:38 -0700
                                                  Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-29 17:25 +0100
                                                    Re: Problem with the function that should display new letter supercat@casperkitty.com - 2015-10-29 12:46 -0700
                                                      Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-30 09:03 +0100
                                                Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-29 19:19 +0000
                                                  Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-30 09:54 +0100
                                                    Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-30 12:20 +0000
                                                Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-29 21:36 +0000
                                                  Re: Problem with the function that should display new letter Ian Collins <ian-news@hotmail.com> - 2015-10-30 10:47 +1300
                                                    Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-29 22:25 +0000
                                                    Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-30 09:59 +0100
                                                  Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-30 10:07 +0100
                          Re: Problem with the function that should display new letter David Brown <david.brown@hesbynett.no> - 2015-10-28 16:25 +0100
                            Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-28 16:01 +0000
                              Re: Problem with the function that should display new letter Keith Thompson <kst-u@mib.org> - 2015-10-28 09:50 -0700
                              Re: Problem with the function that should display new letter glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-10-28 21:57 +0000
                                Re: Problem with the function that should display new letter Geoff <geoff@invalid.invalid> - 2015-10-28 18:25 -0700
                              Re: Problem with the function that should display new letter Geoff <geoff@invalid.invalid> - 2015-10-28 18:23 -0700
                                Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-29 01:44 +0000
              Re: Problem with the function that should display new letter Keith Thompson <kst-u@mib.org> - 2015-10-28 07:07 -0700
            Re: Problem with the function that should display new letter Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-30 07:07 -0700
              Re: Problem with the function that should display new letter Keith Thompson <kst-u@mib.org> - 2015-10-30 09:08 -0700
                Re: Problem with the function that should display new letter Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-30 14:29 -0700
                  Re: Problem with the function that should display new letter Keith Thompson <kst-u@mib.org> - 2015-10-30 16:10 -0700
                    Re: Problem with the function that should display new letter Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-30 20:27 -0700
                      Re: Problem with the function that should display new letter Keith Thompson <kst-u@mib.org> - 2015-10-31 12:40 -0700
                        Re: Problem with the function that should display new letter Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-02 02:16 -0800
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 03:36 -0700
      Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-29 10:46 +0000
        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 03:56 -0700
        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 04:00 -0700
          Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-29 11:02 +0000
            Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 04:05 -0700
              Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-29 11:14 +0000
            Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 04:14 -0700
              Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-29 11:26 +0000
              Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-29 11:26 +0000
                Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 05:29 -0700
                  Re: Problem with the function that should display new letter James Kuyper <jameskuyper@verizon.net> - 2015-10-29 09:23 -0400
                    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 07:44 -0700
                      Re: Problem with the function that should display new letter James Kuyper <jameskuyper@verizon.net> - 2015-10-29 11:39 -0400
                        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 09:52 -0700
                      Re: Problem with the function that should display new letter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-29 16:02 +0000
                        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 09:56 -0700
                          Re: Problem with the function that should display new letter James Kuyper <jameskuyper@verizon.net> - 2015-10-29 13:41 -0400
                            Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-29 17:46 +0000
                              Re: Problem with the function that should display new letter Udyant Wig <udyantw@gmail.com> - 2015-10-30 00:14 +0530
                                Re: Problem with the function that should display new letter raltbos@xs4all.nl (Richard Bos) - 2015-10-29 19:30 +0000
                                  Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-29 22:08 +0000
                                    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 22:28 -0700
                                Re: Problem with the function that should display new letter Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-30 08:10 -0700
                                  Re: Problem with the function that should display new letter supercat@casperkitty.com - 2015-10-30 08:56 -0700
                                    Re: Problem with the function that should display new letter Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-30 13:18 -0700
                              Re: Problem with the function that should display new letter Ian Collins <ian-news@hotmail.com> - 2015-10-30 09:11 +1300
                            Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 01:21 -0700
        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 04:04 -0700
          Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-29 11:11 +0000
            Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 04:19 -0700
              Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-29 11:24 +0000
                Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 05:26 -0700
                  Re: Problem with the function that should display new letter Keith Thompson <kst-u@mib.org> - 2015-10-29 08:31 -0700
              Re: Problem with the function that should display new letter James Kuyper <jameskuyper@verizon.net> - 2015-10-29 09:42 -0400
                Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 08:31 -0700
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-29 10:17 -0700
      Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-29 17:36 +0000
        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 01:18 -0700
          Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 08:36 +0000
            Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 08:38 +0000
            Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 02:26 -0700
              Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 09:32 +0000
                Re: Problem with the function that should display new letter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-30 13:39 +0000
            Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 03:59 -0700
              Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 11:18 +0000
                Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 06:24 -0700
                  Re: Problem with the function that should display new letter James Kuyper <jameskuyper@verizon.net> - 2015-10-30 14:18 -0400
                Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 06:34 -0700
                  Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 13:39 +0000
                    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 06:57 -0700
                      Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-11-01 09:06 +0000
              Re: Problem with the function that should display new letter Keith Thompson <kst-u@mib.org> - 2015-10-30 08:49 -0700
                Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 10:18 -0700
      Re: Problem with the function that should display new letter Barry Schwarz <schwarzb@dqel.com> - 2015-10-29 11:48 -0700
        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 01:23 -0700
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 01:42 -0700
      Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 09:13 +0000
      Re: Problem with the function that should display new letter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-30 10:17 +0000
        Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 10:23 +0000
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 06:39 -0700
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 06:45 -0700
      Re: Problem with the function that should display new letter Richard Heathfield <rjh@cpax.org.uk> - 2015-10-30 13:55 +0000
        Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-30 07:05 -0700
      Re: Problem with the function that should display new letter Steve Thompson <stevet810@gmail.com> - 2015-10-30 23:29 +0000
        Re: Problem with the function that should display new letter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 01:14 +0000
          Re: Problem with the function that should display new letter Steve Thompson <stevet810@gmail.com> - 2015-10-31 17:02 +0000
            Re: Problem with the function that should display new letter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 18:05 +0000
              Re: Problem with the function that should display new letter Steve Thompson <stevet810@gmail.com> - 2015-10-31 23:46 +0000
                Re: Problem with the function that should display new letter supercat@casperkitty.com - 2015-11-01 08:46 -0800
                  Re: Problem with the function that should display new letter Steve Thompson <stevet810@gmail.com> - 2015-11-01 23:43 +0000
                    Re: Problem with the function that should display new letter supercat@casperkitty.com - 2015-11-01 16:05 -0800
                Re: Problem with the function that should display new letter Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 21:41 +0000
                  Re: Problem with the function that should display new letter Steve Thompson <stevet810@gmail.com> - 2015-11-01 22:46 +0000
            Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-31 18:22 +0000
              Re: Problem with the function that should display new letter Steve Thompson <stevet810@gmail.com> - 2015-10-31 23:57 +0000
          Re: Problem with the function that should display new letter Steve Thompson <stevet810@gmail.com> - 2015-10-31 17:20 +0000
        Re: Problem with the function that should display new letter Bartc <bc@freeuk.com> - 2015-10-31 13:38 +0000
          Re: Problem with the function that should display new letter supercat@casperkitty.com - 2015-10-31 11:28 -0700
            Re: Problem with the function that should display new letter Steve Thompson <stevet810@gmail.com> - 2015-11-01 00:06 +0000
          Re: Problem with the function that should display new letter Steve Thompson <stevet810@gmail.com> - 2015-10-31 17:58 +0000
    Re: Problem with the function that should display new letter Alla _ <modelling.data@gmail.com> - 2015-10-31 01:14 -0700

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


#74151

FromAlla _ <modelling.data@gmail.com>
Date2015-10-29 04:04 -0700
Message-ID<464d0dc2-8a9b-4b8e-9fc0-5fc85f3a4292@googlegroups.com>
In reply to#74145
I have tried to add the initial value of j,
but, when called, the program still returns 
segmentation fault: when I type ./nameofprogram,
and don't add anything else in the command line,
it should return 1 and a message "Please, provide
one argment"; or if argv[1] is not a word, but an 
array of numbers, then it should also return 1.
But I get segmentation fault :)

for (i = 0; i < argv_len; i++)
    {
        j = 0;
        
        while(j != '\0')
        {
            if (!isalpha(argv[i][j]))
                return 1;
                
            j++;
        }
    }

Yes, I have header files in the program. I didn't
include them in the previous message to make it shorter.

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


#74153

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-10-29 11:11 +0000
Message-ID<n0supi$stl$1@dont-email.me>
In reply to#74151
On 29/10/15 11:04, Alla _ wrote:
> I have tried to add the initial value of j,
> but, when called, the program still returns
> segmentation fault:

I've already answered this one, but there's just one point...

> Yes, I have header files in the program. I didn't
> include them in the previous message to make it shorter.

Best to leave them in when posting your code. Otherwise, how do we tell 
whether a bug is caused by their being left out? Always post the whole 
program, so that people can easily compile it on their own machines and 
thus make bug-hunting a lot quicker.

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


#74156

FromAlla _ <modelling.data@gmail.com>
Date2015-10-29 04:19 -0700
Message-ID<80702574-7ea1-4ead-862e-e4e13b7490bf@googlegroups.com>
In reply to#74153
On Thursday, October 29, 2015 at 3:11:59 PM UTC+4, Richard Heathfield wrote:
> On 29/10/15 11:04, Alla _ wrote:
> > I have tried to add the initial value of j,
> > but, when called, the program still returns
> > segmentation fault:
> 
> I've already answered this one, but there's just one point...
> 
> > Yes, I have header files in the program. I didn't
> > include them in the previous message to make it shorter.
> 
> Best to leave them in when posting your code. Otherwise, how do we tell 
> whether a bug is caused by their being left out? Always post the whole 
> program, so that people can easily compile it on their own machines and 
> thus make bug-hunting a lot quicker.
> 
> -- 
> 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

All right. I am sometimes confused - do I have to post
the whole program, or just part of it. Sometimes I get
flack (a friendly one) for posting too much of a code. 

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


#74157

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-10-29 11:24 +0000
Message-ID<n0svhu$a3$1@dont-email.me>
In reply to#74156
On 29/10/15 11:19, Alla _ wrote:
> On Thursday, October 29, 2015 at 3:11:59 PM UTC+4, Richard Heathfield wrote:
>> On 29/10/15 11:04, Alla _ wrote:
>>> I have tried to add the initial value of j,
>>> but, when called, the program still returns
>>> segmentation fault:
>>
>> I've already answered this one, but there's just one point...
>>
>>> Yes, I have header files in the program. I didn't
>>> include them in the previous message to make it shorter.
>>
>> Best to leave them in when posting your code. Otherwise, how do we tell
>> whether a bug is caused by their being left out? Always post the whole
>> program, so that people can easily compile it on their own machines and
>> thus make bug-hunting a lot quicker.

> All right. I am sometimes confused - do I have to post
> the whole program, or just part of it. Sometimes I get
> flack (a friendly one) for posting too much of a code.

If you are asking for help with the program, it is only common sense to 
provide the whole of the program you are asking for help with, so that 
people can compile it locally. If people complain, tell them what I told 
you. :-)

While we're on the subject of article length:

When you first started posting, in your replies you would quote every 
single word of the article you were replying to. People (rightly) 
complained. Now, however, you remove *too much*! :-)  The trick is to 
quote the stuff you're actually addressing, and not the stuff you're not 
addressing. Also, leave attribution lines in - for example:

On Tuesday 9th January 2009, Jack Tar said:

so that people can work out who said what.

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


#74161

FromAlla _ <modelling.data@gmail.com>
Date2015-10-29 05:26 -0700
Message-ID<d75f921d-be0e-4cc2-99ec-83acb7c5d056@googlegroups.com>
In reply to#74157
<snip>
> > All right. I am sometimes confused - do I have to post
> > the whole program, or just part of it. Sometimes I get
> > flack (a friendly one) for posting too much of a code.
> 
> If you are asking for help with the program, it is only common sense to 
> provide the whole of the program you are asking for help with, so that 
> people can compile it locally. If people complain, tell them what I told 
> you. :-)

 Yes, Sir! :)

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


#74174

FromKeith Thompson <kst-u@mib.org>
Date2015-10-29 08:31 -0700
Message-ID<ln7fm5bsj0.fsf@kst-u.example.com>
In reply to#74161
Alla _ <modelling.data@gmail.com> writes:
> <snip>
>> > All right. I am sometimes confused - do I have to post
>> > the whole program, or just part of it. Sometimes I get
>> > flack (a friendly one) for posting too much of a code.
>> 
>> If you are asking for help with the program, it is only common sense to 
>> provide the whole of the program you are asking for help with, so that 
>> people can compile it locally. If people complain, tell them what I told 
>> you. :-)
>
>  Yes, Sir! :)

Um, you snipped Richard's advice not to snip the attribution line.
You also snipped the attribution line.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


#74169

FromJames Kuyper <jameskuyper@verizon.net>
Date2015-10-29 09:42 -0400
Message-ID<n0t7jo$u14$1@dont-email.me>
In reply to#74156
On 10/29/2015 07:19 AM, Alla _ wrote:
> On Thursday, October 29, 2015 at 3:11:59 PM UTC+4, Richard Heathfield wrote:
>> On 29/10/15 11:04, Alla _ wrote:
>>> I have tried to add the initial value of j,
>>> but, when called, the program still returns
>>> segmentation fault:
>>
>> I've already answered this one, but there's just one point...
>>
>>> Yes, I have header files in the program. I didn't
>>> include them in the previous message to make it shorter.
>>
>> Best to leave them in when posting your code. Otherwise, how do we tell 
>> whether a bug is caused by their being left out? Always post the whole 
>> program, so that people can easily compile it on their own machines and 
>> thus make bug-hunting a lot quicker.
...
> All right. I am sometimes confused - do I have to post
> the whole program, or just part of it. ...

Do you know what's wrong with your program? If so, post only the part
that's wrong. But if you know what's wrong with your program, why are
you posting a question?
If you don't know what's wrong, you can't be sure which parts can safely
be dropped. For some reason, it seems to very consistently be the case
that when people drop the parts of the program that they think are
irrelevant, they almost invariably drop the most relevant part of the
program.

What if your program is too large to post? That's certainly possible.
What you should do is create a simplified version of your code, cutting
out everything you think is irrelevant. However, always test to make
sure that you still get unexpected behavior. Remember what I said above
about people almost invariably dropping the most relevant part? Don't be
surprised if you have to put something back into the simplified program
that you thought was irrelevant, in order to make it demonstrate the
problem that you're asking about. In fact, that's a vitally important
clue: you should think carefully about why the part you tried to drop
actually was relevant. If you follow this process before posting a
question, you will often find yourself figuring out what the actual
problem was while simplifying the program, before you even get around to
posting your question.

Other things you should always include whenever posting such a question:
1. Identify the platform you're using, the compiler you're using, and
the command line options (if you're compiling at the command line) or
the compiler configuration options (if you're using an GUI IDE to build
a project).
2. Explain what you expected to happen, in sufficient detail so that
it's clear why what actually happened is not what you expected.
3. Copy and paste all of the text output that you have that tells you
that something unexpected happened. If it wouldn't compile, show us the
compilation messages. If it won't link, show us the linker messages. If
it compiles and links but doesn't execute as expected, show us what it
actually did that was unexpected.

> ... Sometimes I get
> flack (a friendly one) for posting too much of a code. 


Ignore that. The only justified criticism is if you showed the wrong
code (and that does happen, more often than seems reasonable).
-- 
James Kuyper

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


#74175

FromAlla _ <modelling.data@gmail.com>
Date2015-10-29 08:31 -0700
Message-ID<6d38ac17-0b0a-4067-b37e-47e02391b6a3@googlegroups.com>
In reply to#74169
On Thursday, October 29, 2015 at 5:42:32 PM UTC+4, James Kuyper wrote:
> On 10/29/2015 07:19 AM, Alla _ wrote:
> > On Thursday, October 29, 2015 at 3:11:59 PM UTC+4, Richard Heathfield wrote:
> >> On 29/10/15 11:04, Alla _ wrote:
> >>> I have tried to add the initial value of j,
> >>> but, when called, the program still returns
> >>> segmentation fault:
> >>
> >> I've already answered this one, but there's just one point...
> >>
> >>> Yes, I have header files in the program. I didn't
> >>> include them in the previous message to make it shorter.
> >>
> >> Best to leave them in when posting your code. Otherwise, how do we tell 
> >> whether a bug is caused by their being left out? Always post the whole 
> >> program, so that people can easily compile it on their own machines and 
> >> thus make bug-hunting a lot quicker.
> ...
> > All right. I am sometimes confused - do I have to post
> > the whole program, or just part of it. ...
> 
> Do you know what's wrong with your program? If so, post only the part
> that's wrong. But if you know what's wrong with your program, why are
> you posting a question?
> If you don't know what's wrong, you can't be sure which parts can safely
> be dropped. For some reason, it seems to very consistently be the case
> that when people drop the parts of the program that they think are
> irrelevant, they almost invariably drop the most relevant part of the
> program.
> 
> What if your program is too large to post? That's certainly possible.
> What you should do is create a simplified version of your code, cutting
> out everything you think is irrelevant. However, always test to make
> sure that you still get unexpected behavior. Remember what I said above
> about people almost invariably dropping the most relevant part? Don't be
> surprised if you have to put something back into the simplified program
> that you thought was irrelevant, in order to make it demonstrate the
> problem that you're asking about. In fact, that's a vitally important
> clue: you should think carefully about why the part you tried to drop
> actually was relevant. If you follow this process before posting a
> question, you will often find yourself figuring out what the actual
> problem was while simplifying the program, before you even get around to
> posting your question.
> 
> Other things you should always include whenever posting such a question:
> 1. Identify the platform you're using, the compiler you're using, and
> the command line options (if you're compiling at the command line) or
> the compiler configuration options (if you're using an GUI IDE to build
> a project).
> 2. Explain what you expected to happen, in sufficient detail so that
> it's clear why what actually happened is not what you expected.
> 3. Copy and paste all of the text output that you have that tells you
> that something unexpected happened. If it wouldn't compile, show us the
> compilation messages. If it won't link, show us the linker messages. If
> it compiles and links but doesn't execute as expected, show us what it
> actually did that was unexpected.
> 
> > ... Sometimes I get
> > flack (a friendly one) for posting too much of a code. 
> 
> 
> Ignore that. The only justified criticism is if you showed the wrong
> code (and that does happen, more often than seems reasonable).
> -- 
> James Kuyper

Thank you. I am trying to follow this rules, and will
correct myself.

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


#74185

FromAlla _ <modelling.data@gmail.com>
Date2015-10-29 10:17 -0700
Message-ID<afd643cc-d26b-4034-80ae-a7ed01387771@googlegroups.com>
In reply to#73976
I am skipping the argv part for now, because
I still need more time to ponder over it - 
can't solve it yet. 

Meanwhile, this program has produced other
issues that I have overlooked.

Algorithm to clarify what the program should do:

1) the user should type ./name_of_the_program and 
key_word (only one key_word_) at the command line

2) if there is more than 1 word after the name of
the program, or if there are no key_words at all, i.e. if argc > 2,
or if argc < 2, the program returns 1, and exits

3) otherwise, the program prompts the user for a 
text message.

4) using vigenere algorithm the program cipher the text:

- each letter of original text should be converted by
the index of a corresponding letter in the key_word; index
starts from 0;

- if at some point the program hits non-alphabetical character
in the original text, it should print that as it is, and
also stop incrementing index; renew incementing when the next letter
is met;

- if the key_word is shorter than the original text, it should be
wrapped around; thus, for example, if the key_word is 'baz' and text
is 'amazing', then baz fits amazing by being wrapped few times:
a m a z i n g
b a z b a z b

I am posting 2 versions - none produce correct outcome.

The 1st one has the problem with incrementing i-s: the program
increments i-s no matter what type of character is present.
Hence the outcome:
text 'world, say hello!' with key word 'baz' becomes
      xoqmd, szz qflkp!  but has to be 'xoqmd, rby qflkp!'

The difference is only in 'rby' part which happens because of 
incorrect incrementing of i-s.

In 2nd version I am trying to correct that, but
get the wrong result (I also have a 3d version with a while loop,
but I don't think it is appropriate here).

2d version gives xoqmd, say hello!

1) //** Program to cipher the text based on vigenere algorithm **/

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

void new_text(char text[], char key_word[]);

int main (int argc, char *argv[])
{
    char message[80];
    
    if (argc == 1 || argc > 2)
    {
        printf("\a");
        printf("Please, provide one argument - a word\n");
        return 1;
    }
    
    else
    {
        char *key = argv[1];
        
        printf("Please, enter your message: \n");
        
        if (fgets (message, sizeof message, stdin) != NULL)
            new_text(message, key);
    }
    
    return 0;
}

void new_text(char text[], char key_word[])
{
    int i;
    int len = strlen(text);
    int key_len = strlen(key_word);
    int key_index;
    char new_letter;
    
    for (i = 0; i < len; i++)
    {        
        if (isalpha (text[i]))
        {
            int letter = text[i];
            
            if (islower (letter))
            {
                if (islower(key_word[i % key_len]))
                    
                    key_index = key_word[i % key_len] - 'a';
                
                if (isupper(key_word[i % key_len]))
                    
                        key_index = key_word[i % key_len] - 'A';
                
                new_letter = (letter - 'a' + key_index) % 26 + 'a';
            }
            
            if (isupper (letter))
            {   
                if (islower(key_word[i % key_len]))
                    
                    key_index = key_word[i % key_len] - 'a';
                
                if (isupper(key_word[i % key_len]))
                    
                    key_index = key_word[i % key_len] - 'A';
                
                new_letter = (letter - 'A' + key_index) % 26 + 'A';
            }
            
            printf("%c", new_letter);
        }
        
        else
            printf("%c", text[i]);
        
    }
    printf ("\n");
}

2nd version:

//** Program to cipher the text based on vigenere algorithm **/

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

void new_text(char text[], char key_word[]);

int main (int argc, char *argv[])
{
    char message[80];
    
    if (argc == 1 || argc > 2)
    {
        printf("\a");
        printf("Please, provide one argument - a word\n");
        return 1;
    }
    
    else
    {
        char *key = argv[1];
        
        printf("Please, enter your message: \n");
        
        if (fgets (message, sizeof message, stdin) != NULL)
            new_text(message, key);
    }
    
    return 0;
}

void new_text(char text[], char key_word[])
{
    int i;
    int j = 0;
    int len = strlen(text);
    int key_len = strlen(key_word);
    int key_index;
    char new_letter;
    
    for (i = 0; i < len; i++)
    {
        if (isalpha (text[j]))
        {
            int letter = text[j];
            
            if (islower (letter))
            {
                if (islower(key_word[j % key_len]))
                    
                    key_index = key_word[j % key_len] - 'a';
                
                if (isupper(key_word[j % key_len]))
                    
                        key_index = key_word[j % key_len] - 'A';
                
                new_letter = (letter - 'a' + key_index) % 26 + 'a';
            }
            
            if (isupper (letter))
            {   
                if (islower(key_word[j % key_len]))
                    
                    key_index = key_word[j % key_len] - 'a';
                
                if (isupper(key_word[j % key_len]))
                    
                    key_index = key_word[j % key_len] - 'A';
                
                new_letter = (letter - 'A' + key_index) % 26 + 'A';
            }
            
            printf("%c", new_letter);
            
            j++;
        }
        
        else
            printf("%c", text[i]);
        
    }
    printf ("\n");
}

Thank you!

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


#74186

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-10-29 17:36 +0000
Message-ID<n0tlbg$ppp$1@dont-email.me>
In reply to#74185
On 29/10/15 17:17, Alla _ wrote:
> I am skipping the argv part for now, because
> I still need more time to ponder over it -
> can't solve it yet.

In an attempt to slow you down a bit, I will show you your first bug 
only. Not your most important bug, or your most difficult bug, but your 
*first* bug.

When you've fixed that, I'll look again.

>      if (argc == 1 || argc > 2)
>      {
>          printf("\a");
>          printf("Please, provide one argument - a word\n");
>          return 1;
>      }
>
>      else
>      {
>          char *key = argv[1];

Here's your first bug.

It is perfectly possible for argc to be 0. In such a circumstance, 
argv[0] will be a null pointer, and so char *key will be assigned a null 
pointer, which in due course you pass to strlen without further checking.

What you want is *exactly one* argument other than the program name. 
That is, you want argc to be 2.

So don't ask if it's 1 or > 2. Just ask whether it's 2!

   if(argc == 2)
   {
      do your thing
   }
   else
   {
      complain and quit
   }

Let me know when you've understood that point and fixed your code 
accordingly.

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


#74238

FromAlla _ <modelling.data@gmail.com>
Date2015-10-30 01:18 -0700
Message-ID<95eee1d9-fbe1-4cc9-b9c7-3ee2e6c917da@googlegroups.com>
In reply to#74186
> It is perfectly possible for argc to be 0. In such a circumstance, 
> argv[0] will be a null pointer, and so char *key will be assigned a null 
> pointer, which in due course you pass to strlen without further checking.
> 
> What you want is *exactly one* argument other than the program name. 
> That is, you want argc to be 2.
> 
> So don't ask if it's 1 or > 2. Just ask whether it's 2!
> 
>    if(argc == 2)
>    {
>       do your thing
>    }
>    else
>    {
>       complain and quit
>    }
> 
Of course! I should have come with such efficient codes
myself by now. Fail too often. But I get happy when I find 
these types of bugs, or style defects. Ifs are powerful in
this sense. Learning efficiency is one of my side goals. 

Thank you! 

> Let me know when you've understood that point and fixed your code 
> accordingly.

Done. :) 

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


#74241

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-10-30 08:36 +0000
Message-ID<n0va1k$36m$1@dont-email.me>
In reply to#74238
On 30/10/15 08:18, Alla _ wrote:
>

<snip>

>
>> Let me know when you've understood that point and fixed your code
>> accordingly.
>
> Done. :)

Okay. It would have been handy for you to post the revised source code, 
but I guess we can cope without it this one time.

Your next problem is that your main() function is way too busy.

You wish to determine whether a string consists entirely of alphabetic 
characters. Rather than write code in main() to do that, why not ship it 
out to another function?

BartC suggested this earlier in the thread. Although I rarely agree with 
what BartC says, on this occasion he is correct.

Here is a possible candidate for that function:

#include <stddef.h>
#include <ctype.h>

int is_word(const char *s) /* add "const" to your "learn-later" list */
{
   int word = 0; /* it can't be a word, unless it's non-null */
   if(s != NULL)
   {
     word = 1; /* it's a word unless it has non-alphabetics */
     while(word != 0 && *s != '\0')
     {
       word = (isalpha(*s++);
     }
   }
   return word;
}

You could now use this function in main(), where it replaces an entire 
loop. You can eliminate the /other/ loop by realising that you don't 
need to check any argv other than argv[1]. This gives you a rather 
simple main():

   if(argc == 2)
   {
     if(is_word(argv[1]))
     {
       char message[80] = "";
       char *key = argv[1];
       printf("Please enter your message\n");
       if(fgets(message, sizeof message, stdin) != NULL)
       {
         new_text(message, key);
       }
     }
   }

You see how much cleaner it is?

Your next job is to do a similar clean-up for new_text(), which is a 
mess. Once you've simplified it, post the new program and we can have 
another look at 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]


#74243

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-10-30 08:38 +0000
Message-ID<n0va6d$36m$2@dont-email.me>
In reply to#74241
On 30/10/15 08:36, Richard Heathfield wrote:

>        word = (isalpha(*s++);

          word = isalpha(*s++);

What was that I said about spotting bugs after hitting Send?

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


#74256

FromAlla _ <modelling.data@gmail.com>
Date2015-10-30 02:26 -0700
Message-ID<7399120d-cca6-40b9-8968-ffb0de887da4@googlegroups.com>
In reply to#74241
On Friday, October 30, 2015 at 12:36:19 PM UTC+4, Richard Heathfield wrote:
> On 30/10/15 08:18, Alla _ wrote:
> >
> 
> <snip>
> 
> >
> >> Let me know when you've understood that point and fixed your code
> >> accordingly.
> >
> > Done. :)
> 
> Okay. It would have been handy for you to post the revised source code, 
> but I guess we can cope without it this one time.
> 
> Your next problem is that your main() function is way too busy.
> 
> You wish to determine whether a string consists entirely of alphabetic 
> characters. Rather than write code in main() to do that, why not ship it 
> out to another function?
> 
> BartC suggested this earlier in the thread. Although I rarely agree with 
> what BartC says, on this occasion he is correct.
> 
> Here is a possible candidate for that function:
> 
> #include <stddef.h>
> #include <ctype.h>
> 
> int is_word(const char *s) /* add "const" to your "learn-later" list */
> {
>    int word = 0; /* it can't be a word, unless it's non-null */
>    if(s != NULL)
>    {
>      word = 1; /* it's a word unless it has non-alphabetics */
>      while(word != 0 && *s != '\0')
>      {
>        word = (isalpha(*s++);
>      }
>    }
>    return word;
> }
> 
> You could now use this function in main(), where it replaces an entire 
> loop. You can eliminate the /other/ loop by realising that you don't 
> need to check any argv other than argv[1]. This gives you a rather 
> simple main():
> 
>    if(argc == 2)
>    {
>      if(is_word(argv[1]))
>      {
>        char message[80] = "";
>        char *key = argv[1];
>        printf("Please enter your message\n");
>        if(fgets(message, sizeof message, stdin) != NULL)
>        {
>          new_text(message, key);
>        }
>      }
>    }
> 
> You see how much cleaner it is?
> 
> Your next job is to do a similar clean-up for new_text(), which is a 
> mess. Once you've simplified it, post the new program and we can have 
> another look at it.

Thank you very much! I am doing it now.

The only thing I should ask you for: although I am
yet not capable of producing such clean and easy functions
as the one you have just presented, please, do not give out
the whole thing, because this way you are doing a job for me,
which is not ethically correct, and also how will I be able to 
make my brains work if you just give out the decision for me? :)))

Of course, function you write are very helpful because I do learn 
a lot when I study codes you suggest. And I am actually looking into the one
Bart has suggested, the structured one. 

I will now revise the program and post it. Please, ignore
my last message with the next_text function (except for 
the part where I explain what I am doing with that function).

Thank you so much!!!

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


#74257

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-10-30 09:32 +0000
Message-ID<n0vdb4$ddf$1@dont-email.me>
In reply to#74256
On 30/10/15 09:26, Alla _ wrote:
> On Friday, October 30, 2015 at 12:36:19 PM UTC+4, Richard Heathfield wrote:
<snip>
>>
>> Your next job is to do a similar clean-up for new_text(), which is a
>> mess. Once you've simplified it, post the new program and we can have
>> another look at it.
>
> Thank you very much! I am doing it now.

I'm looking forward to seeing that code.

>
> The only thing I should ask you for: although I am
> yet not capable of producing such clean and easy functions
> as the one you have just presented, please, do not give out
> the whole thing, because this way you are doing a job for me,
> which is not ethically correct, and also how will I be able to
> make my brains work if you just give out the decision for me? :)))

I'm not doing a job for you. I'm showing you a way of thinking. That's 
far more important than the specific details of a particular exercise. 
You make your brains work by reading what I've written, comparing it to 
what you've written, and identifying in what ways mine is an improvement 
(if any - which is for you to decide). Where you can see that my way is 
cleaner, simpler, faster, more elegant, whatever you want to call it, 
you can adopt that way of programming for yourself. And where you think 
it's dirtier, more complicated, slower, less elegant, you can perhaps 
ask questions about why I did it in that particular way. Either way 
involves you *thinking* and *learning*.

> Of course, function you write are very helpful because I do learn
> a lot when I study codes you suggest.

And that's exactly why I post such code. And that's why I then asked you 
to do the same clean-up job on new_text().

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


#74300

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-10-30 13:39 +0000
Message-ID<87pozweaqi.fsf@bsb.me.uk>
In reply to#74257
Richard Heathfield <rjh@cpax.org.uk> writes:

> On 30/10/15 09:26, Alla _ wrote:
<snip>
>> The only thing I should ask you for: although I am
>> yet not capable of producing such clean and easy functions
>> as the one you have just presented, please, do not give out
>> the whole thing, because this way you are doing a job for me,
>> which is not ethically correct, and also how will I be able to
>> make my brains work if you just give out the decision for me? :)))
>
> I'm not doing a job for you. I'm showing you a way of thinking. That's
> far more important than the specific details of a particular
> exercise. You make your brains work by reading what I've written,
> comparing it to what you've written, and identifying in what ways mine
> is an improvement (if any - which is for you to decide). Where you can
> see that my way is cleaner, simpler, faster, more elegant, whatever
> you want to call it, you can adopt that way of programming for
> yourself.

One way to do this would be for the person learning C to say that
they've finished with and exercise for now and that they are going to
move one.  Anyone who cares to can then write up their own solution for
comparison (and Collective Criticism).  I'm not sure if anyone would
post, but it's possible.

I would have liked to have that when I was learning.  We could get to
see the work of some fellow students (an advantage that self-learners
like Alla do not have) and, if we were lucky, we'd get one "model
answer" from the teacher.

<snip>
-- 
Ben.

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


#74266

FromAlla _ <modelling.data@gmail.com>
Date2015-10-30 03:59 -0700
Message-ID<6baf970d-7cc6-4a52-a6a9-bd2a90b26310@googlegroups.com>
In reply to#74241
Here is the full program. The program doesn't work,
I would be happy to find my error, but I don't see it.
It compiles without warnings (I use a long compiling message
now). When I enter './name baz' nothing happens. 

//** Program to cipher the text based on vigenere algorithm **/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stddef.h>
/** If I understand correctly, in the case of this program, stddef.h 
 is required for the NULL value used in is_word function; isn't NULL also a 
 part of stdio.h library? **/

int is_word(const char *string);
int word_index(const char *text, const char *word);
void new_text(char text[], char key_word[]);

int main (int argc, char *argv[])
{
    char message[80];
    
    if (argc == 2)
    {
        if (is_word(argv[1])) /** if is_word returns 1, i.e. is TRUE, then
                               do the following; if is_word returns zero, then go
                               to else part **/
        {
            char *key = argv[1];
        
            printf("Please, enter your message: \n");
        
            if (fgets (message, sizeof message, stdin) != NULL)
            {
                new_text(message, key);
            }
        }
    }
    
    else
    {
        printf("\a");
        printf("Please, provide one argument - a word\n");
        return 1;
    }

    return 0;
}
            
int is_word(const char *string)
{
    int word = 0;
    
    if (string != NULL)
    {
        word = 1;
        
        while(word != 0 && word != '\0')
        {
            word = (isalpha(*string++)); /** the pointer refers to the address of the first
                                          character, hence *string++ is used **/
                                         /** if the string is not an alphabetical one, then
                                          isalpha returns 0, the while loop terminates, and 
                                          the function returns 0 as the value of the word**/
        }
    }
    
    return word;
}

int word_index(const char *text, const char *word)
{
    int i, index;
    int j = 0;
    int word_len = strlen(word);
    int text_len = strlen(text);
    
    for(i = 0; i < text_len; i++)
    {
        if (isalpha(text[i]))
        {
            if (islower(word[j % word_len]))
            {
                index = word[j % word_len] - 'a';
            }
        
            if (isupper(word[j % word_len]))
            {
                index = word[j % word_len] - 'A';
            }
            j++;
        }
    }
    
    return index;
}

void new_text(char text[], char key_word[])
{
    int i;
    int len = strlen(text);
    char new_letter;
    
    for (i = 0; i < len; i++)
    {
        if (isalpha (text[i]))
        {
            int letter = text[i];
            
            if (islower (letter))
            {
                new_letter = (letter - 'a' + word_index(text, key_word)) % 26 + 'a';
            }
            
            if (isupper (letter))
            {
                new_letter = (letter - 'A' + word_index(text, key_word)) % 26 + 'A';
            }
            
            printf("%c", new_letter);
        }
        
        else
            printf("%c", text[i]);
    }
    printf ("\n");
}

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


#74269

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-10-30 11:18 +0000
Message-ID<n0vjho$3ba$1@dont-email.me>
In reply to#74266
On 30/10/15 10:59, Alla _ wrote:
> Here is the full program. The program doesn't work,
> I would be happy to find my error, but I don't see it.
> It compiles without warnings (I use a long compiling message
> now). When I enter './name baz' nothing happens.
>
> //** Program to cipher the text based on vigenere algorithm **/
>
> #include <stdio.h>
> #include <string.h>
> #include <ctype.h>
> #include <stddef.h>
> /** If I understand correctly, in the case of this program, stddef.h
>   is required for the NULL value used in is_word function; isn't NULL also a
>   part of stdio.h library? **/

Firstly, <stdio.h> is not a library; it's a header. The distinction is a 
very important one. Headers contain interface information for the 
compiler. Libraries contain implementations of functions (in object file 
format).

Secondly, NULL is defined in a number of headers, including <stdio.h> 
and <stddef.h> - if you already have <stdio.h>, you don't need to 
include <stddef.h> for NULL.

> int is_word(const char *string);
> int word_index(const char *text, const char *word);
> void new_text(char text[], char key_word[]);
>

main looks more or less fine now.

> int is_word(const char *string)
> {
>      int word = 0;
>
>      if (string != NULL)
>      {
>          word = 1;
>
>          while(word != 0 && word != '\0')

Um, what? Why are you testing word against 0 *twice*? Do you think that 
it might pass the first test against 0 but somehow fail the next test 
against 0 immediately after?

I think you meant to write:

     while(word != 0 && *string != '\0')

I have a question for you.

In my proposed code for is_word(), I wrote a test:

   while(word != 0 && *s != '\0')

That is: for as long as we haven't ruled out the possibility that this 
is a word, AND as long as we have some string left...

You changed it to read:

   while(word != 0 && word != '\0')

That is: for as long as we haven't ruled out the possibility that this 
is a word, AND as long as we haven't ruled out the possibility that this 
isn't a word...

What prompted you to make that change? Why did you think it was a good 
idea to remove the check on the string contents (a vital check) and 
replace it with a /second/ check on whether the 'word' flag had been set?

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


#74291

FromAlla _ <modelling.data@gmail.com>
Date2015-10-30 06:24 -0700
Message-ID<871945c1-c02c-43f8-a0f5-5bb1df716690@googlegroups.com>
In reply to#74269
On Friday, October 30, 2015 at 3:18:35 PM UTC+4, Richard Heathfield wrote:
> On 30/10/15 10:59, Alla _ wrote:
> > Here is the full program. The program doesn't work,
> > I would be happy to find my error, but I don't see it.
> > It compiles without warnings (I use a long compiling message
> > now). When I enter './name baz' nothing happens.
> >
> > //** Program to cipher the text based on vigenere algorithm **/
> >
> > #include <stdio.h>
> > #include <string.h>
> > #include <ctype.h>
> > #include <stddef.h>
> > /** If I understand correctly, in the case of this program, stddef.h
> >   is required for the NULL value used in is_word function; isn't NULL also a
> >   part of stdio.h library? **/
> 
> Firstly, <stdio.h> is not a library; it's a header. The distinction is a 
> very important one. Headers contain interface information for the 
> compiler. Libraries contain implementations of functions (in object file 
> format).
> 
> Secondly, NULL is defined in a number of headers, including <stdio.h> 
> and <stddef.h> - if you already have <stdio.h>, you don't need to 
> include <stddef.h> for NULL.
> 
> > int is_word(const char *string);
> > int word_index(const char *text, const char *word);
> > void new_text(char text[], char key_word[]);
> >
> 
> main looks more or less fine now.
> 
> > int is_word(const char *string)
> > {
> >      int word = 0;
> >
> >      if (string != NULL)
> >      {
> >          word = 1;
> >
> >          while(word != 0 && word != '\0')
> 
> Um, what? Why are you testing word against 0 *twice*? Do you think that 
> it might pass the first test against 0 but somehow fail the next test 
> against 0 immediately after?
> 
> I think you meant to write:
> 
>      while(word != 0 && *string != '\0')
> 
> I have a question for you.
> 
> In my proposed code for is_word(), I wrote a test:
> 
>    while(word != 0 && *s != '\0')
> 
> That is: for as long as we haven't ruled out the possibility that this 
> is a word, AND as long as we have some string left...
> 
> You changed it to read:
> 
>    while(word != 0 && word != '\0')
> 
> That is: for as long as we haven't ruled out the possibility that this 
> is a word, AND as long as we haven't ruled out the possibility that this 
> isn't a word...
> 
> What prompted you to make that change? Why did you think it was a good 
> idea to remove the check on the string contents (a vital check) and 
> replace it with a /second/ check on whether the 'word' flag had been set?
> 
usual human inveterate habit for typos, or whatever its called
when you mean one thing but write another :) I had no intention
of changing what you have proposed, because I have clearly understood 
your code. 

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


#74353

FromJames Kuyper <jameskuyper@verizon.net>
Date2015-10-30 14:18 -0400
Message-ID<n10c4r$smi$1@dont-email.me>
In reply to#74291
On 10/30/2015 09:24 AM, Alla _ wrote:
> On Friday, October 30, 2015 at 3:18:35 PM UTC+4, Richard Heathfield wrote:
>> On 30/10/15 10:59, Alla _ wrote:
...
>>>          while(word != 0 && word != '\0')
>>
>> Um, what? Why are you testing word against 0 *twice*? Do you think that 
>> it might pass the first test against 0 but somehow fail the next test 
>> against 0 immediately after?
>>
>> I think you meant to write:
>>
>>      while(word != 0 && *string != '\0')
...
> usual human inveterate habit for typos, or whatever its called
> when you mean one thing but write another :) I had no intention
> of changing what you have proposed, because I have clearly understood 
> your code. 

It occurred to me that this typo would be a lot easier to commit if
you're unaware that 0 == '\0'. Were you aware of that?
-- 
James Kuyper

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


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

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


csiph-web