Re: [DNG] [OT] Re: Studying C as told. (For help)

2016-06-23 Thread Irrwahn
On Thu, 23 Jun 2016 08:23:01 +0100, Katolaz wrote: [...] > Thanks for your explanation :) Actually, my point was simply that the > language allows you to do whatever you want with allocated space that > you think is "an array of T". If I remove the explicit casts, the > compiler gives a few warning

[DNG] [OT] Re: Studying C as told. (For help)

2016-06-23 Thread KatolaZ
On Thu, Jun 23, 2016 at 02:42:13AM +0200, Irrwahn wrote: [cut] > > Actually, I think it in fact /still/ invokes undefined behavior, > as it is only valid to cast from a pointer-to-T to a pointer to a > compatible type (and back), or from a pointer-to-T to void pointer > (or a pointer-to-unsign

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Steve Litt
On Tue, 21 Jun 2016 14:43:03 -0400 "Steven W. Scott" wrote: > May as well toss in the assembler guy approach to the problem: > > char SpaceSquash() > { > for (i = strlen(desc) - 1; i > 0; i--) { >if (desc[i-1] == ' ') { >if (desc[i] == ' ') { >

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Steve Litt
On Tue, 21 Jun 2016 14:43:03 -0400 "Steven W. Scott" wrote: > May as well toss in the assembler guy approach to the problem: > > char SpaceSquash() > { > for (i = strlen(desc) - 1; i > 0; i--) { >if (desc[i-1] == ' ') { >if (desc[i] == ' ') { >

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Rainer Weikusat
Adam Borowski writes: > On Tue, Jun 21, 2016 at 03:13:21PM +0200, Irrwahn wrote: >> On Tue, 21 Jun 2016 14:42:46 +0200, Edward Bartolo wrote: >> [...] >> > if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { >> [...] >> You should *never* assume that the latin letters occur in >> the exec

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Irrwahn
On Tue, 21 Jun 2016 21:30:34 +0100, Katolaz wrote: > Nono, wait guys. > > 1 octet == 1 byte == 8 bits Not so. Although the 8-bit byte today is a de facto standard for most of the equipment in wide use, it is not set in stone, lest is it defined that way. So it's actually: 1 octet == 8 b

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Steve Litt
On Tue, 21 Jun 2016 17:55:52 +0100 KatolaZ wrote: > On Tue, Jun 21, 2016 at 06:41:15PM +0200, Edward Bartolo wrote: > > [cut] > > > > > And > > << if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) >> > > > > would reduce to: > > > > if (isletter(c)) > > > > or, you could just use "is

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread KatolaZ
On Tue, Jun 21, 2016 at 10:16:21PM +0200, Irrwahn wrote: [cut] > > >> And "there's so much broken code already you rely on" should > >> never be an excuse to deliberately produce even more broken code. > > > > I wouldn't call code that assumes 8-bit bytes "broken". I'd call it "sane". > > Oc

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Irrwahn
On Tue, 21 Jun 2016 14:43:03 -0400, Steven W. Scott wrote: > May as well toss in the assembler guy approach to the problem: > > char SpaceSquash() > { > for (i = strlen(desc) - 1; i > 0; i--) { >if (desc[i-1] == ' ') { >if (desc[i] == ' ') { >

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Irrwahn
On Tue, 21 Jun 2016 21:50:10 +0200, Adam Borowski wrote: > It's isalpha() that's an abomination, exactly because its behaviour varies > between locales. That depends on the requirements. There are cases where I as a user would be slightly surprised if some code would tell me that e.g. Umlauts

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread KatolaZ
On Tue, Jun 21, 2016 at 09:57:06PM +0200, Adam Borowski wrote: > On Tue, Jun 21, 2016 at 05:55:52PM +0100, KatolaZ wrote: > > On Tue, Jun 21, 2016 at 06:41:15PM +0200, Edward Bartolo wrote: > > > And > > > << if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) >> > > > > > > would reduce to: > >

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Adam Borowski
On Tue, Jun 21, 2016 at 05:55:52PM +0100, KatolaZ wrote: > On Tue, Jun 21, 2016 at 06:41:15PM +0200, Edward Bartolo wrote: > > And > > << if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) >> > > > > would reduce to: > > > > if (isletter(c)) > > or, you could just use "isalpha(c)", as suggest

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Adam Borowski
On Tue, Jun 21, 2016 at 04:38:50PM +0200, Irrwahn wrote: > On Tue, 21 Jun 2016 16:00:53 +0200, Adam Borowski wrote: > > On Tue, Jun 21, 2016 at 03:13:21PM +0200, Irrwahn wrote: > >> On Tue, 21 Jun 2016 14:42:46 +0200, Edward Bartolo wrote: > >> [...] > >>> if ((c >= 'a' && c <= 'z') || (c >= 'A

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Steven W. Scott
May as well toss in the assembler guy approach to the problem: char SpaceSquash() { for (i = strlen(desc) - 1; i > 0; i--) { if (desc[i-1] == ' ') { if (desc[i] == ' ') { strncpy(&desc[i], &desc[i+1], (strlen(desc)-i));

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Irrwahn
On Tue, 21 Jun 2016 17:55:52 +0100, Katolaz wrote: > On Tue, Jun 21, 2016 at 06:41:15PM +0200, Edward Bartolo wrote: > > [cut] > >> >> And >> << if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) >> >> >> would reduce to: >> >> if (isletter(c)) >> > > or, you could just use "isalpha(c)", as s

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread KatolaZ
On Tue, Jun 21, 2016 at 06:41:15PM +0200, Edward Bartolo wrote: [cut] > > And > << if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) >> > > would reduce to: > > if (isletter(c)) > or, you could just use "isalpha(c)", as suggested also by Urban. -- [ ~.,_ Enzo Nicosia aka KatolaZ -

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Edward Bartolo
Hi, Irrwhan35 wrote: << [...] > if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { [...] You should *never* assume that the latin letters occur in the execution character set in ascending consecutive order. (Though similar *is* guaranteed for the digits '0' to '9'!) >> I think a function

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Irrwahn
On Tue, 21 Jun 2016 16:00:53 +0200, Adam Borowski wrote: > On Tue, Jun 21, 2016 at 03:13:21PM +0200, Irrwahn wrote: >> On Tue, 21 Jun 2016 14:42:46 +0200, Edward Bartolo wrote: >> [...] >>> if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { >> [...] >> You should *never* assume that the la

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Adam Borowski
On Tue, Jun 21, 2016 at 03:13:21PM +0200, Irrwahn wrote: > On Tue, 21 Jun 2016 14:42:46 +0200, Edward Bartolo wrote: > [...] > > if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { > [...] > You should *never* assume that the latin letters occur in > the execution character set in ascendin

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Irrwahn
On Tue, 21 Jun 2016 14:42:46 +0200, Edward Bartolo wrote: [...] > if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { [...] You should *never* assume that the latin letters occur in the execution character set in ascending consecutive order. (Though similar *is* guaranteed for the digits '

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Irrwahn
On Tue, 21 Jun 2016 13:15:57 +0100, Simon Hobson wrote: > http://www.ioccc.org Supplemental readings: https://www.doc.ic.ac.uk/~susan/475/unmain.html http://xkcd.com/1513/ http://xkcd.com/1695/ ___ Dng mailing list Dng@lists.dyne.org https://ma

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Edward Bartolo
Hi, Again, this is NOT a difficulty but for anyone wanting to comment. And this is for P. 38 Exercise 1-14 Initially, this gave me the dreaded Segmentation Fault (aka Access Violation). It was naturally something to do with the array. I was exceeding the permissible index maximum. My solution:

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Simon Hobson
Irrwahn wrote: > We could. But it is a kludge, and very bad style. Is this the right time to introduce ... ... wait for it ... ... you're probably not going to like it ... ... no spoilers ... ... it is "safe for work" ... ... unless your work is writing C code ... http://www.io

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Edward Bartolo
Hi, This is NOT a difficulty. I am posting my code so that anyone wanting to comment can do so. Pg 38, Exercise: 1-13 Write a program to print a histogram of the lengths of words in its input. Horizontal bars selected. My solution/code: #include int main() { #define MAX_LENGTH 10 int word

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Irrwahn
On Tue, 21 Jun 2016 19:31:55 +0900, Simon Walter wrote: [About short-circuiting logical operators] > I am thinking we might use single ampersand or pipe (bitwise). Can we > use bitwise operators as what would be a non-short-circuiting logical > operator in C (or other languages)? We could. But i

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Simon Walter
On 06/21/2016 06:09 PM, KatolaZ wrote: On Tue, Jun 21, 2016 at 05:47:59PM +0900, Simon Walter wrote: [cut] Be careful, because conditional expressions in C are subject to "short-circuiting", meaning that only the minimum number of expressions sufficient to determine the value of a chain of &&

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread KatolaZ
On Tue, Jun 21, 2016 at 05:47:59PM +0900, Simon Walter wrote: [cut] > >Be careful, because conditional expressions in C are subject to > >"short-circuiting", meaning that only the minimum number of > >expressions sufficient to determine the value of a chain of && and || > >will be evaluated. In p

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Simon Hobson
KatolaZ wrote: > Be careful, because conditional expressions in C are subject to > "short-circuiting", meaning that only the minimum number of > expressions sufficient to determine the value of a chain of && and || > will be evaluated. In particular, a chain of || expressions will be > evaluated

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread Simon Walter
On 06/21/2016 05:28 PM, KatolaZ wrote: On Tue, Jun 21, 2016 at 08:22:41AM +0200, Edward Bartolo wrote: [cut] I studied 'and' and 'or' boolean operators back when I studied Delphi Pascal. I am embarrassed to have written such a stupid thing. It must be due to the fact I wrote the email just

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-21 Thread KatolaZ
On Tue, Jun 21, 2016 at 08:22:41AM +0200, Edward Bartolo wrote: [cut] > > I studied 'and' and 'or' boolean operators back when I studied Delphi > Pascal. I am embarrassed to have written such a stupid thing. It must > be due to the fact I wrote the email just before going to bed. > > AND: requi

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-20 Thread Edward Bartolo
Hi, I wrote: << This is the previous version compressed by using another && operand in the boolean expressions. The final sub-expression is an assignment, which always evaluates to true provided the other two sub-expressions evaluate to true. The final statement uses a similar strategy to compress

Re: [DNG] [OT] [Re: Studying C as told. (For help)

2016-06-20 Thread KatolaZ
On Mon, Jun 20, 2016 at 04:27:12PM +0100, KatolaZ wrote: [cut] > > which can be further streched into: > ^ I obviously meant "squeezed into" HND KatolaZ -- [ ~.,_ Enzo Nicosia aka KatolaZ - GLUGCT -- Freaknet Medialab ] [ "+. katolaz [at] freaknet.o

[DNG] [OT] [Re: Studying C as told. (For help)

2016-06-20 Thread KatolaZ
On Mon, Jun 20, 2016 at 04:37:08PM +0200, Edward Bartolo wrote: [cut] > > On page Page 34 Exercise 1-9 > "Write a program to copy its input to its output, replacing each > string of blanks one ore more blanks by a single blank." > > I wrote the following, tested it, and it seems to work, but I