Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #73976 > unrolled thread
| Started by | Alla _ <modelling.data@gmail.com> |
|---|---|
| First post | 2015-10-27 09:52 -0700 |
| Last post | 2015-10-31 01:14 -0700 |
| Articles | 20 on this page of 174 — 20 participants |
Back to article view | Back to comp.lang.c
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 2 of 9 — ← Prev page 1 [2] 3 4 5 6 7 8 9 Next page →
| From | "D. Aaron Sawyer" <aaron@110.net> |
|---|---|
| Date | 2015-10-27 13:40 -0400 |
| Message-ID | <n0ocqg$i1g$1@dont-email.me> |
| In reply to | #73976 |
On 2015.10.27 12:52, Alla _ wrote:
> Hello!
>
> Please, take a look at a program that is supposed
> to take the message (for now the message is given
> with main function), and based on the value of some
> key display the same message with letters produced
> by 'original letter + key'.
>
> I have an issue with one part of this program, which
> fail to produce the desired outcome. This part should
> do the following:
>
> /** if the value of the sum 'original letter + key' is bigger
> than the value of 'z' (lower case) or 'Z' (upper case),
> then the value of the expression
> '(original letter + key)%26' is assigned to the new letter **/
>
> The program does convert characters when the sum of 'original letter
> + key' is within the range of 'a - z' or 'A-Z', and it
> does display any other character unchanged (special characters, digits)
> as it should. But it fails to produce the result I named above.
>
...[snipped]...
> Program:
> /** Program to cipher the text **/
>
> #include <stdio.h>
> #include <string.h>
> #include <ctype.h>
>
> char alpha_low[] = "abcdefghijklmnopqrstuvwxyz";
> char alpha_up[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>
...[snipped]...
>
> int look_up (int alpha_letter)
> {
> int i;
>
> for (i = 1; i < 27; i++)
> {
> if (alpha_low [i] == alpha_letter || alpha_up [i] == alpha_letter)
> return i;
> }
> }
>
[snipped]
Please note that in C, arrays are indexed from 0, not 1.
The return value from look_up() is one greater than it should be.
Also, for future consideration: what is returned from look_up() if the argument alpha_letter is not,
in fact, an alphabetic letter character? What should be returned, if anything?
[toc] | [prev] | [next] | [standalone]
| From | "D. Aaron Sawyer" <aaron@110.net> |
|---|---|
| Date | 2015-10-27 13:47 -0400 |
| Message-ID | <n0od7d$jad$1@dont-email.me> |
| In reply to | #73982 |
On 2015.10.27 13:40, D. Aaron Sawyer wrote:
> On 2015.10.27 12:52, Alla _ wrote:
>> Hello!
>>
>> Please, take a look at a program that is supposed
>> to take the message (for now the message is given
>> with main function), and based on the value of some
>> key display the same message with letters produced
>> by 'original letter + key'.
>>
>> I have an issue with one part of this program, which
>> fail to produce the desired outcome. This part should
>> do the following:
>>
>> /** if the value of the sum 'original letter + key' is bigger
>> than the value of 'z' (lower case) or 'Z' (upper case),
>> then the value of the expression
>> '(original letter + key)%26' is assigned to the new letter **/
>>
>> The program does convert characters when the sum of 'original letter
>> + key' is within the range of 'a - z' or 'A-Z', and it
>> does display any other character unchanged (special characters, digits)
>> as it should. But it fails to produce the result I named above.
>>
> ...[snipped]...
>> Program:
>> /** Program to cipher the text **/
>>
>> #include <stdio.h>
>> #include <string.h>
>> #include <ctype.h>
>>
>> char alpha_low[] = "abcdefghijklmnopqrstuvwxyz";
>> char alpha_up[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>>
> ...[snipped]...
>>
>> int look_up (int alpha_letter)
>> {
>> int i;
>>
>> for (i = 1; i < 27; i++)
>> {
>> if (alpha_low [i] == alpha_letter || alpha_up [i] == alpha_letter)
>> return i;
>> }
>> }
>>
> [snipped]
>
> Please note that in C, arrays are indexed from 0, not 1.
> The return value from look_up() is one greater than it should be.
Also, what happens when the argument to look_up() is the letter "A"? Or the letter "a"?
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-27 11:38 -0700 |
| Message-ID | <05848a45-68a1-490d-b994-a3b8edbff3b3@googlegroups.com> |
| In reply to | #73983 |
On Tuesday, October 27, 2015 at 9:47:39 PM UTC+4, D. Aaron Sawyer wrote:
> On 2015.10.27 13:40, D. Aaron Sawyer wrote:
> > On 2015.10.27 12:52, Alla _ wrote:
> >> Hello!
> >>
> >> Please, take a look at a program that is supposed
> >> to take the message (for now the message is given
> >> with main function), and based on the value of some
> >> key display the same message with letters produced
> >> by 'original letter + key'.
> >>
> >> I have an issue with one part of this program, which
> >> fail to produce the desired outcome. This part should
> >> do the following:
> >>
> >> /** if the value of the sum 'original letter + key' is bigger
> >> than the value of 'z' (lower case) or 'Z' (upper case),
> >> then the value of the expression
> >> '(original letter + key)%26' is assigned to the new letter **/
> >>
> >> The program does convert characters when the sum of 'original letter
> >> + key' is within the range of 'a - z' or 'A-Z', and it
> >> does display any other character unchanged (special characters, digits)
> >> as it should. But it fails to produce the result I named above.
> >>
> > ...[snipped]...
> >> Program:
> >> /** Program to cipher the text **/
> >>
> >> #include <stdio.h>
> >> #include <string.h>
> >> #include <ctype.h>
> >>
> >> char alpha_low[] = "abcdefghijklmnopqrstuvwxyz";
> >> char alpha_up[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> >>
> > ...[snipped]...
> >>
> >> int look_up (int alpha_letter)
> >> {
> >> int i;
> >>
> >> for (i = 1; i < 27; i++)
> >> {
> >> if (alpha_low [i] == alpha_letter || alpha_up [i] == alpha_letter)
> >> return i;
> >> }
> >> }
> >>
> > [snipped]
> >
> > Please note that in C, arrays are indexed from 0, not 1.
> > The return value from look_up() is one greater than it should be.
>
> Also, what happens when the argument to look_up() is the letter "A"? Or the letter "a"?
The index returned is 0. Therefore, (0 + key) % 26 should produce
a correct index anyway.
Is it wrong?
[toc] | [prev] | [next] | [standalone]
| From | "D. Aaron Sawyer" <aaron@110.net> |
|---|---|
| Date | 2015-10-27 16:46 -0400 |
| Message-ID | <n0onnl$vd7$1@dont-email.me> |
| In reply to | #73989 |
On 2015.10.27 14:38, Alla _ wrote:
> On Tuesday, October 27, 2015 at 9:47:39 PM UTC+4, D. Aaron Sawyer wrote:
>> On 2015.10.27 13:40, D. Aaron Sawyer wrote:
>>> On 2015.10.27 12:52, Alla _ wrote:
>>>> Hello!
>>>>
>>>> Please, take a look at a program that is supposed
>>>> to take the message (for now the message is given
>>>> with main function), and based on the value of some
>>>> key display the same message with letters produced
>>>> by 'original letter + key'.
>>>>
>>>> I have an issue with one part of this program, which
>>>> fail to produce the desired outcome. This part should
>>>> do the following:
>>>>
>>>> /** if the value of the sum 'original letter + key' is bigger
>>>> than the value of 'z' (lower case) or 'Z' (upper case),
>>>> then the value of the expression
>>>> '(original letter + key)%26' is assigned to the new letter **/
>>>>
>>>> The program does convert characters when the sum of 'original letter
>>>> + key' is within the range of 'a - z' or 'A-Z', and it
>>>> does display any other character unchanged (special characters, digits)
>>>> as it should. But it fails to produce the result I named above.
>>>>
>>> ...[snipped]...
>>>> Program:
>>>> /** Program to cipher the text **/
>>>>
>>>> #include <stdio.h>
>>>> #include <string.h>
>>>> #include <ctype.h>
>>>>
>>>> char alpha_low[] = "abcdefghijklmnopqrstuvwxyz";
>>>> char alpha_up[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>>>>
>>> ...[snipped]...
>>>>
>>>> int look_up (int alpha_letter)
>>>> {
>>>> int i;
>>>>
>>>> for (i = 1; i < 27; i++)
>>>> {
>>>> if (alpha_low [i] == alpha_letter || alpha_up [i] == alpha_letter)
>>>> return i;
>>>> }
>>>> }
>>>>
>>> [snipped]
>>>
>>> Please note that in C, arrays are indexed from 0, not 1.
>>> The return value from look_up() is one greater than it should be.
>>
>> Also, what happens when the argument to look_up() is the letter "A"? Or the letter "a"?
>
> The index returned is 0. Therefore, (0 + key) % 26 should produce
> a correct index anyway.
> Is it wrong?
>
You have modified look_up() to return 0 elsewhere in this discussion. However, consider the function as
quoted (and originally posted). If the letter 'A' were passed to this function, at what value of i will
the conditional evaluate to true (and what value of i will be returned)?
By starting the loop index at 1, the 'A' will be compared against 'b' (alpha_low[1]) and then against 'B'
(alpha_up[1]). No matches, no return. Bump the loop index to 2. Continue incrementing to 26. All compares
have failed so far. At i=26, 'A' is compared to 'z' and then 'Z'. No matches, no return.
Now increment the loop index to 27. Since i is no longer < 27, the for loop exits. What happens next?
There is no return statement, but the function must return an int value.
This ought to have been a compile-time error, but is now a run-time error.
Some compilers may provide a 0 value as the return at this point, but that just means that you, the
programmer, got lucky. You could just as easily have seen a return value of -3649 or 1777935092.
Forcing a return value of 0 (as done later) deals with leaving the for loop without having matched.
BUT it does not deal with the incorrect indexing of the C arrays. Please try rewriting look_up to use
correct C array indexing.
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-27 11:39 -0700 |
| Message-ID | <c8fdc6de-2124-4598-8bc5-c5705584a98c@googlegroups.com> |
| In reply to | #73982 |
> Also, for future consideration: what is returned from look_up() if the argument alpha_letter is not, > in fact, an alphabetic letter character? What should be returned, if anything? I hope that my program has excluded that option, because look_up function is called only for alphabetical characters
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2015-10-27 18:20 +0000 |
| Message-ID | <n0of4h$rjm$1@dont-email.me> |
| In reply to | #73976 |
On 27/10/15 16:52, Alla _ wrote: > Hello! > > Please, take a look at a program that is supposed > to take the message (for now the message is given > with main function), Whoa, what happened to your "initial letters" thing? Don't you think you should fix that first? -- 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]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-27 11:36 -0700 |
| Message-ID | <58967880-d6a7-4346-9921-d11fe13b4659@googlegroups.com> |
| In reply to | #73985 |
On Tuesday, October 27, 2015 at 10:20:24 PM UTC+4, Richard Heathfield wrote: > On 27/10/15 16:52, Alla _ wrote: > > Hello! > > > > Please, take a look at a program that is supposed > > to take the message (for now the message is given > > with main function), > > Whoa, what happened to your "initial letters" thing? Don't you think you > should fix that first? > > -- > 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 Richard, I am working on these few ones now. I have made initials that fit the task, although as usual, I did even much more than was required. Still not satisfied, and I have left it for tomorrow, or a bit later, because I do have trouble with those short conditions in if statements. As you and others have said, I do inefficiently rush ahead, doing and "learning" new things before basics settled down. As with either this basic program, which helps to test conditionals and other aspects, and initials one, I have one thing I want to use (though, again, beyond required by the task), but I still don't know how to do that. Therefore, I am doing easier things first, and trying to be patient and to get to the moment when I am able to fix more complicated issues.
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-27 12:09 -0700 |
| Message-ID | <3f57162c-d44d-49af-8fc0-6425e1b1d780@googlegroups.com> |
| In reply to | #73985 |
On Tuesday, October 27, 2015 at 10:20:24 PM UTC+4, Richard Heathfield wrote: > On 27/10/15 16:52, Alla _ wrote: > > Hello! > > > > Please, take a look at a program that is supposed > > to take the message (for now the message is given > > with main function), > > Whoa, what happened to your "initial letters" thing? Don't you think you > should fix that first? > > -- > 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 I also have a very interesting program (interesting to me because of educational purposes), which I have started discussing here a few weeks ago, and which I have not yet finished, because I need to have a little more understanding of basics we have been discussing during these weeks. Unfortunately, I am too slow in understanding and learning. I have yet another book now, which is written for people like me, who don't have prior programming knowledge. I hope it will also help me :) Thank you so much! I wouldn't know so much as I do now if not your huge help, and help of other members.
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-27 11:51 -0700 |
| Message-ID | <b7a45c28-800f-4736-beda-ce0a2b568d5a@googlegroups.com> |
| In reply to | #73976 |
I was so worried that, although everything worked, this part seemed to be wrong, and even after I added 'new_letter = alpha_up[(look_up(letter) + key) % 26];' the outcome "looked" incorrect, being objectively correct :) I am so sorry, and very thankful for the patience, and help!
[toc] | [prev] | [next] | [standalone]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Date | 2015-10-27 19:25 +0000 |
| Message-ID | <n0oivr$c2d$1@dont-email.me> |
| In reply to | #73976 |
On 27/10/2015 16:52, Alla _ wrote:
> /** Program to cipher the text **/
OK, this is a good clue as to what it might do! Because it's not that
easy to follow otherwise.
> char alpha_low[] = "abcdefghijklmnopqrstuvwxyz";
> char alpha_up[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>
> int look_up (int alpha_letter);
> void new_text(char text[], int key);
>
> int main (void)
> {
> char message[] = "AmaZIng World''::;;";
> /** a bizzare looking message only to check the function **/
>
> int key = 4;
But a fuller explanation would help. It might also make it easier to
code. I /think/ what your program is attempting is this:
* Take the original text string ('plaintext' I think it's called)
* Take one letter at a time
* If it's A to Z, then rotate it by 'key' positions. So is key is 1, the
'Y'=>'Z', and 'Z'='A'.
* If it's a to z, then the same, but rotate within the lower case set.
* Any other characters are unchanged
It wouldn't hurt either to make some assumptions, as you can change this
later:
(1) key is not going to be more than +26 shifts
(2) You will only work with the 52 letters of A to Z and a to z
(3) That ASCII is being used, so that A to Z have consecutive values (65
to 90), and so do a to z (97 to 112). This would greatly simplify your
lookup() routine.
(Presumably, there will be a decipher function at some point that
applies the same key in reverse, so that 'A'=>'Z' etc.)
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-27 12:27 -0700 |
| Message-ID | <b19da732-dcbc-4e78-abbb-a56d7f7877a7@googlegroups.com> |
| In reply to | #73976 |
I have tried to compile the program on my virtual machine,
and got an interesting error (I will post the final program below):
error: control may reach end of non-void function -werror -wreturn-type
Searching for this error produced a few answers, which led me
to adding 'return 0;' at the end of look_up function.
Unfortunately, I didn't understand what is meant by this error,
and why additional return outside the for loop helped to solve it.
/** Program to cipher the text **/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
char alpha_low[] = "abcdefghijklmnopqrstuvwxyz";
char alpha_up[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int look_up (int alpha_letter);
void new_text(char text[], int key);
int main (int argc, char *argv[])
{
char message[80];
if (argc == 1 || argc > 2)
{
printf("\a");
printf("Please, provide one argument\n");
return 1;
}
else
{
int key = atoi(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[], int key)
{
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))
{
/** if letter is in the lower case **/
/** if a sum of a given ascii value of the i-th letter and
the value of the key is within values representing alphabetical
characters in ascii, then new letter should be the letter whose
ascii value is equal to 'letter + key' **/
if( (letter + key) >= 'a' && (letter + key) <= 'z' )
new_letter = letter + key;
/** if the value of 'letter + key' is bigger than the value
of 'z' (lower case), then the value of the remainder is
assigned to the new letter **/
if ( (letter + key) > 'z')
new_letter = alpha_low[(look_up(letter) + key) % 26];
/** function 'look_up(letter)' should return the index value
of a given alphabetical letter **/
}
if(isupper (letter))
{
if( (letter + key) >= 'A' && (letter + key) <= 'Z')
new_letter = letter + key;
if ( (letter + key) > 'Z')
new_letter = alpha_up[(look_up(letter) + key) % 26];
}
printf("%c", new_letter);
}
else
printf("%c", text[i]);
}
printf ("\n");
}
int look_up (int alpha_letter)
{
int i;
for (i = 0; i < 26; i++)
{
if (alpha_low [i] == alpha_letter || alpha_up [i] == alpha_letter)
return i;
}
return 0;
}
Thank you!
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2015-10-28 10:07 +1300 |
| Message-ID | <d9a7ctFg1b3U1@mid.individual.net> |
| In reply to | #73997 |
Alla _ wrote:
> I have tried to compile the program on my virtual machine,
> and got an interesting error (I will post the final program below):
>
> error: control may reach end of non-void function -werror -wreturn-type
>
> Searching for this error produced a few answers, which led me
> to adding 'return 0;' at the end of look_up function.
> Unfortunately, I didn't understand what is meant by this error,
> and why additional return outside the for loop helped to solve it.
<snip>
> int look_up (int alpha_letter)
> {
> int i;
>
> for (i = 0; i < 26; i++)
> {
> if (alpha_low [i] == alpha_letter || alpha_up [i] == alpha_letter)
> return i;
> }
> return 0;
> }
The compiler was warning you that without the last return it thought
that you could get through the loop without a match. If nothing
matched, the code would get to the end of the function without returning
a value. This would case random gibberish to be returned from the function.
This is a good warning to enable, it makes you consider the case where a
match isn't found. This may not be possible in your code, but the
compiler doesn't know that.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-28 00:50 -0700 |
| Message-ID | <34ba9d6a-42ad-4d2d-9405-5c46b98369b8@googlegroups.com> |
| In reply to | #74013 |
On Wednesday, October 28, 2015 at 1:07:55 AM UTC+4, Ian Collins wrote:
> Alla _ wrote:
> > I have tried to compile the program on my virtual machine,
> > and got an interesting error (I will post the final program below):
> >
> > error: control may reach end of non-void function -werror -wreturn-type
> >
> > Searching for this error produced a few answers, which led me
> > to adding 'return 0;' at the end of look_up function.
> > Unfortunately, I didn't understand what is meant by this error,
> > and why additional return outside the for loop helped to solve it.
>
> <snip>
>
> > int look_up (int alpha_letter)
> > {
> > int i;
> >
> > for (i = 0; i < 26; i++)
> > {
> > if (alpha_low [i] == alpha_letter || alpha_up [i] == alpha_letter)
> > return i;
> > }
> > return 0;
> > }
>
> The compiler was warning you that without the last return it thought
> that you could get through the loop without a match. If nothing
> matched, the code would get to the end of the function without returning
> a value. This would case random gibberish to be returned from the function.
>
> This is a good warning to enable, it makes you consider the case where a
> match isn't found. This may not be possible in your code, but the
> compiler doesn't know that.
>
> --
> Ian Collins
Thank you. When used in main function, 'return 0' means
that the function did perform its task correctly. Does
return 0 mean the same in the look_up function?
I don't understand what return 0 means within look_up
function. I understand that it comes into play if there is no
match, as you said, but what does it say?
Thank you!
> This is a good warning to enable, it makes you consider the case where a
> match isn't found. This may not be possible in your code, but the
> compiler doesn't know that.
>
As Richard has pointed out, I do have to enable certain
warnings, but before that I have to learn how to do that :)
Will get to that.
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2015-10-28 21:04 +1300 |
| Message-ID | <d9bdrlFg1b3U3@mid.individual.net> |
| In reply to | #74045 |
Alla _ wrote:
> On Wednesday, October 28, 2015 at 1:07:55 AM UTC+4, Ian Collins wrote:
>> Alla _ wrote:
>>> I have tried to compile the program on my virtual machine,
>>> and got an interesting error (I will post the final program below):
>>>
>>> error: control may reach end of non-void function -werror -wreturn-type
>>>
>>> Searching for this error produced a few answers, which led me
>>> to adding 'return 0;' at the end of look_up function.
>>> Unfortunately, I didn't understand what is meant by this error,
>>> and why additional return outside the for loop helped to solve it.
>>
>> <snip>
>>
>>> int look_up (int alpha_letter)
>>> {
>>> int i;
>>>
>>> for (i = 0; i < 26; i++)
>>> {
>>> if (alpha_low [i] == alpha_letter || alpha_up [i] == alpha_letter)
>>> return i;
>>> }
>>> return 0;
>>> }
>>
>> The compiler was warning you that without the last return it thought
>> that you could get through the loop without a match. If nothing
>> matched, the code would get to the end of the function without returning
>> a value. This would case random gibberish to be returned from the function.
>>
>> This is a good warning to enable, it makes you consider the case where a
>> match isn't found. This may not be possible in your code, but the
>> compiler doesn't know that.
>
> Thank you. When used in main function, 'return 0' means
> that the function did perform its task correctly. Does
> return 0 mean the same in the look_up function?
From the code it looks like it means the letter was 'a' or 'A', so 0
isn't a good return value if the character isn't found in the array, is it?
> I don't understand what return 0 means within look_up
> function. I understand that it comes into play if there is no
> match, as you said, but what does it say?
You should pick a value that indicated an error to the caller. Given a
successful return is > 0, -1 would be a sensible choice.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-28 01:13 -0700 |
| Message-ID | <47ad17bb-51ae-4fab-843b-ed1d07489010@googlegroups.com> |
| In reply to | #74046 |
On Wednesday, October 28, 2015 at 12:04:17 PM UTC+4, Ian Collins wrote:
> Alla _ wrote:
> > On Wednesday, October 28, 2015 at 1:07:55 AM UTC+4, Ian Collins wrote:
> >> Alla _ wrote:
> >>> I have tried to compile the program on my virtual machine,
> >>> and got an interesting error (I will post the final program below):
> >>>
> >>> error: control may reach end of non-void function -werror -wreturn-type
> >>>
> >>> Searching for this error produced a few answers, which led me
> >>> to adding 'return 0;' at the end of look_up function.
> >>> Unfortunately, I didn't understand what is meant by this error,
> >>> and why additional return outside the for loop helped to solve it.
> >>
> >> <snip>
> >>
> >>> int look_up (int alpha_letter)
> >>> {
> >>> int i;
> >>>
> >>> for (i = 0; i < 26; i++)
> >>> {
> >>> if (alpha_low [i] == alpha_letter || alpha_up [i] == alpha_letter)
> >>> return i;
> >>> }
> >>> return 0;
> >>> }
> >>
> >> The compiler was warning you that without the last return it thought
> >> that you could get through the loop without a match. If nothing
> >> matched, the code would get to the end of the function without returning
> >> a value. This would case random gibberish to be returned from the function.
> >>
> >> This is a good warning to enable, it makes you consider the case where a
> >> match isn't found. This may not be possible in your code, but the
> >> compiler doesn't know that.
> >
> > Thank you. When used in main function, 'return 0' means
> > that the function did perform its task correctly. Does
> > return 0 mean the same in the look_up function?
>
> From the code it looks like it means the letter was 'a' or 'A', so 0
> isn't a good return value if the character isn't found in the array, is it?
>
> > I don't understand what return 0 means within look_up
> > function. I understand that it comes into play if there is no
> > match, as you said, but what does it say?
>
> You should pick a value that indicated an error to the caller. Given a
> successful return is > 0, -1 would be a sensible choice.
>
> --
> Ian Collins
Thank you. I understand it now.
[toc] | [prev] | [next] | [standalone]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Date | 2015-10-28 10:40 +0000 |
| Message-ID | <n0q8jg$oa6$1@dont-email.me> |
| In reply to | #74046 |
On 28/10/2015 08:04, Ian Collins wrote:
> Alla _ wrote:
>>>> int look_up (int alpha_letter)
>>>> {
>>>> int i;
>>>>
>>>> for (i = 0; i < 26; i++)
>>>> {
>>>> if (alpha_low [i] == alpha_letter || alpha_up [i] ==
>>>> alpha_letter)
>>>> return i;
>>>> }
>>>> return 0;
>>>> }
>> Thank you. When used in main function, 'return 0' means
>> that the function did perform its task correctly. Does
>> return 0 mean the same in the look_up function?
>
> From the code it looks like it means the letter was 'a' or 'A', so 0
> isn't a good return value if the character isn't found in the array, is it?
>
>> I don't understand what return 0 means within look_up
>> function. I understand that it comes into play if there is no
>> match, as you said, but what does it say?
>
> You should pick a value that indicated an error to the caller. Given a
> successful return is > 0, -1 would be a sensible choice.
This is one of those cases where an exception can be made. A-Z are
commonly numbered 1 to 26 in all sorts of situations. (If you had to tap
N times on the metal pipe in your cell to communicate one of A to Z,
then 0 taps for A makes that awkward.)
So a return of i+1 would be simplest (with adjustments in the caller).
Then 0 can mean failure (or non-alphabetical).
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2015-10-28 11:02 +0000 |
| Message-ID | <n0q9rs$s9m$1@dont-email.me> |
| In reply to | #74058 |
On 28/10/15 10:40, Bartc wrote: > On 28/10/2015 08:04, Ian Collins wrote: <snip> >> You should pick a value that indicated an error to the caller. Given a >> successful return is > 0, -1 would be a sensible choice. > > This is one of those cases where an exception can be made. An exception can be made in just about every case, but that doesn't make it a good idea. > A-Z are > commonly numbered 1 to 26 in all sorts of situations. (If you had to tap > N times on the metal pipe in your cell to communicate one of A to Z, > then 0 taps for A makes that awkward.) But a C program is not a metal pipe in a cell. Alla is currently trying to adjust to 0-based arrays, which is an absolutely essential part of learning C programming. Don't make her take a backward step. -- 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]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-10-28 11:28 +0000 |
| Message-ID | <87wpu7grkw.fsf@bsb.me.uk> |
| In reply to | #74058 |
Bartc <bc@freeuk.com> writes:
> On 28/10/2015 08:04, Ian Collins wrote:
>>>> Alla _ wrote:
<snip>
>>>>> int look_up (int alpha_letter)
>>>>> {
>>>>> int i;
>>>>>
>>>>> for (i = 0; i < 26; i++)
>>>>> {
>>>>> if (alpha_low [i] == alpha_letter || alpha_up [i] ==
>>>>> alpha_letter)
>>>>> return i;
>>>>> }
>>>>> return 0;
>>>>> }
<snip>
>> You should pick a value that indicated an error to the caller. Given a
>> successful return is > 0, -1 would be a sensible choice.
>
> This is one of those cases where an exception can be made. A-Z are
> commonly numbered 1 to 26 in all sorts of situations. (If you had to
> tap N times on the metal pipe in your cell to communicate one of A to
> Z, then 0 taps for A makes that awkward.)
The program is not going to tap anything out. It's going to do modular
arithmetic on the result and then index that array again. Both are
naturally 0-based operations.
> So a return of i+1 would be simplest (with adjustments in the
> caller).
How is returning i+1 simpler than returning i? Also, the most
significant adjustment required in the caller will be to subtract the 1
you are suggesting should be added. It makes no sense.
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Date | 2015-10-28 11:57 +0000 |
| Message-ID | <n0qd3e$8ca$1@dont-email.me> |
| In reply to | #74065 |
On 28/10/2015 11:28, Ben Bacarisse wrote: > Bartc <bc@freeuk.com> writes: >> This is one of those cases where an exception can be made. A-Z are >> commonly numbered 1 to 26 in all sorts of situations. (If you had to >> tap N times on the metal pipe in your cell to communicate one of A to >> Z, then 0 taps for A makes that awkward.) > > The program is not going to tap anything out. It's going to do modular > arithmetic on the result and then index that array again. Both are > naturally 0-based operations. > >> So a return of i+1 would be simplest (with adjustments in the >> caller). > > How is returning i+1 simpler than returning i? Is the caller going to check the result? Then it needs to be decided whether lookup returns 0 to 25 on success, and -1 etc on failure, or 1 to 26 on success, and 0 on failure. In the latter case, returning i+1 is simpler (Another way is to offset the array so that 'A' starts at element [1]. Then the need to have A=0 for the purpose of indexing disappears.) > Also, the most > significant adjustment required in the caller will be to subtract the 1 > you are suggesting should be added. It makes no sense. It depends on what the caller wants to do. It could also make it easier to think about the logic when A is represented by 1, B by 2 etc. That might be better than having 0 representing A forced on you because in one place in the code, it has to do modular arithmetic, which can probably be done with an if-statement just as easily. -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2015-10-28 12:53 +0000 |
| Message-ID | <n0qgd1$kgs$1@dont-email.me> |
| In reply to | #74069 |
On 28/10/15 11:57, Bartc wrote: > On 28/10/2015 11:28, Ben Bacarisse wrote: >> Bartc <bc@freeuk.com> writes: > >>> This is one of those cases where an exception can be made. A-Z are >>> commonly numbered 1 to 26 in all sorts of situations. (If you had to >>> tap N times on the metal pipe in your cell to communicate one of A to >>> Z, then 0 taps for A makes that awkward.) >> >> The program is not going to tap anything out. It's going to do modular >> arithmetic on the result and then index that array again. Both are >> naturally 0-based operations. >> >>> So a return of i+1 would be simplest (with adjustments in the >>> caller). >> >> How is returning i+1 simpler than returning i? > > Is the caller going to check the result? Yes. > Then it needs to be decided > whether lookup returns 0 to 25 on success, and -1 etc on failure, or 1 > to 26 on success, and 0 on failure. if((idx = lookup(ch)) < 0) it failed - easy. > > In the latter case, returning i+1 is simpler (Another way is to offset > the array so that 'A' starts at element [1]. Then the need to have A=0 > for the purpose of indexing disappears.) I tried it your way, and had to think very, very hard about the indexing. When I do it the proper way, I don't need to, because the indexing is blindingly obvious. >> Also, the most >> significant adjustment required in the caller will be to subtract the 1 >> you are suggesting should be added. It makes no sense. > > It depends on what the caller wants to do. It also depends on what the programmer wants to do. The programmer wants to learn C programming, and will be far better served by learning about 0-based arrays than about ways to circumvent them and complicate the program in the process. -- 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]
Page 2 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