HDTenEightyP/NetNews huggingface dataset:
From: gordon@osiris.cso.uiuc.edu (John Gordon)
Subject: Re: getch
Organization: University of Illinois at Urbana
Date: Sun, 15 Nov 1992 17:41:24 GMT

c60c-2gf@web-2a.berkeley.edu () writes:


>At home, I run a version of Turbo C on my IBM.  There is a library function
>with a prototype in conio.h called getch (and getche).  Is there an 
>equivalent of this function on standard Unix systems.  I'm on a Sun, I 
>believe (not a Sparc station though).  This question may be really
>obvious, but I am not quite sure how all the specifics with input/output
>work on the system (i.e. x-window control etc.) and I can't quite seem
>to find getch.  The man page goes on and on abou'curses,' but I am still
>pretty lost.  Any help would be appreciated (in email, please).  Thanks

	The function you want is getchar().  Unfortunately, in the default
mode of most (all?) terminals, getchar() will not return a value until
ENTER has been pressed.  Fortunately, you can change the mode of the
terminal so that it will read 1 character without waiting for ENTER.  (This
is called "raw mode", and the default is "cooked mode", if you care.)

	Here is a function that works for me.  It runs under DYNIX/ptx,
which is a POSIX-compliant variant of UNIX SYSV.  If you are running
under a Berkeley-type UNIX, it might need some changing.  Anyway, here's
the function:

------------------------------------------------
/*
   Getkey.c

   Written 01/16/1991 by John Gordon, adapted from code supplied by Tim Evans

   The purpose of this program is to set ioctl to "raw" mode, read a keypress,
   reset the ioctl mode, and return the character read.

   History:
   01/16/91 by John Gordon - initial version adapted from Tim's code
*/

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

int getkey()
{
  int c;
  struct termio tsav, tchg;

  if (ioctl(0, TCGETA, &tsav) == -1)
  {
    perror("getkey: can't get original settings");
    exit(2);
  }

  tchg = tsav;

  tchg.c_lflag &= ~(ICANON | ECHO);
  tchg.c_cc[VMIN] = 1;
  tchg.c_cc[VTIME] = 0;

  if (ioctl(0, TCSETA, &tchg) == -1)
  { 
    perror("getkey: can't initiate new settings");
    exit (3);
  }

  c = getchar();

  if(ioctl( 0, TCSETA, &tsav) == -1)
  {
    perror("getkey: can't reset original settings");
    exit(4);
  }

  return(c);

} /* end getkey() */
------------------------------------------------

Enjoy.

---
John Gordon                        My incredibly witty saying has been 
gordon@osiris.cso.uiuc.edu         Politically Corrected into oblivion.
Newsgroups: comp.lang.c,comp.software-eng
From: johnson@cs.uiuc.edu (Ralph Johnson)
Subject: Re: Will we keep ignoring this productivity issue?
Organization: University of Illinois, Dept. of Comp. Sci., Urbana, IL
Date: Tue, 17 Nov 1992 21:26:23 GMT

shanks@saifr00.cfsat.honeywell.com (Mark Shanks) writes:

>> Can love of programming be taught?

>No, no more than fastidiousness can be taught, or leadership, or
>to stretch, musical genius, superior athletic ability, or how to
>write a best seller.

>I maintain that superior
>programming ability is inherent; it can be developed in those who
>who have it, but you can't teach it any more than you could turn a
>tennis star into a stock broker or an orchestral conductor into 
>a neurosurgeon.

You can teach fastidiousness (my wife teaches it to my children),
you can teach leadership, you can teach musical talent and athletic
ability.  You can teach writing, you can teach playing tennis, you
can teach how to be a stock broker, you can teach how to conduct
an orchestra and how to be a neurosurgeon.   Sure, you can't teach
EVERYBODY how to do it, and, in general, it takes so much time to
be good at anything that people have to pick one thing and then
spend most of their life concentrating on it.  But it is just silly
to claim that all things in life are inherent and cannot be taught.

The same is true of programming.  If you are going to be good at
something then you must work hard.  The reason that there are so
many good black basketball players is because there are boys in
inner cities who practice half of each day for years at a time.
Some of them have the genetic gifts to be taller and faster than
most of their peers, but even the short ones develop phenomenal
skills.  Practice, hard work, and desire are the main attributes
necessary to developing skill.  That's why most of the superprogrammers
love to program.  They practice because they love it, not because they
are forced to.  Love leads to practice which leads to skill.
However, I know a few very good pianists who practiced for the first
four or five years of their life because their parents made them;
love came later, after they started to enjoy their skills.

Becoming a good programmer requires lots of practice.  It also requires
education in the fundamentals.  It also requires native ability.  That
native ability is pretty much the same as that shared by all engineers
and mathematicians.  I think the reason that so many engineers and
mathematicians are poor programmers is because of poor training and
lack of practice, NOT because of lack of ability.

Ralph Johnson -- University of Illinois at Urbana-Champaign
From: rene@hamel.uucp (Rene Mueller)
Newsgroups: comp.lang.c
Subject: Re: How to use 'return' in c?
Date: 19 Nov 92 15:26:02 GMT
Organization: Free University of Berlin, Germany

In article <1992Oct29.053625.24495@u.washington.edu>, chuckb@stein.u.washington.edu (Charles Bass) writes:
|> As for exit(1) and exit(0) it is safest to use the constants
|> EXIT_SUCCESS and EXIT_FAILURE so the proper value is returned to
|> the OS
Doesn't work on every OS...
There are a lot of compilers where these defines doesn't exist...

	Rene
Newsgroups: comp.lang.c
From: hollasch@kpc.com (Steve Hollasch)
Subject: Re: What is meant by: double A[n,m]?
Summary: Confusing, perhaps, but not meaningless.
Organization: Kubota Pacific Computer, Inc.
Date: Wed, 18 Nov 1992 22:39:00 GMT

torstein@itekiris.kjemi.unit.no (torstein hansen) writes:
> As a newcomer to C, previously programming in Pascal, I used the
> following declaration in one of my programs:
> 
> double A[n,m];
>
> Has it something to do with the comma operator, discarding the first
> value inside the braces?

jlothian@castle.ed.ac.uk (J Lothian) writes:
| I suspect that's exactly what's happening. The comma operator
| evaluates both its arguments, returning the value of the right-
| hand expression and throwing away the value of the left-hand one.
| Presumably your C compiler is quite happy to do this evaluation
| at compile-time, though I'm a little surprised that it didn't flag
| this as an error, given that in this context the construction is
| bound to be meaningless. 

    Not true.  First of all, the expression "A[index]" is not evaluated at
compile time, nor is "A[flag,index]"; both of these will be evaluated at
run time.  Nor is this construct meaningless - consider the following
fragment:

        return error_msgs [global_errno = ERR_SOMETHING, getindex()];

where
        
        error_msgs is an array of pointers to error messages,
        global_errno is some encoded error value,
        and getindex() is a function that returns the error message index
            based on global_errno.

    A completely contrived example, but it should demonstrate that using a
comma operator within an array subscript is not meaningless (though some
might object to the above construct for reasons of style).

______________________________________________________________________________
Steve Hollasch                                   Kubota Pacific Computer, Inc.
hollasch@kpc.com                                 Santa Clara, California
From: dkeisen@leland.Stanford.EDU (Dave Eisen)
Newsgroups: comp.lang.c
Subject: Re: Pointer to a short struct????
Date: 18 Nov 92 23:49:47 GMT
Distribution: usa
Organization: Sequoia Peripherals, Inc.

In article <1eeeeiINNae6@rave.larc.nasa.gov> alan@hal.larc.nasa.gov (alan dare) writes:
>
>	I am mapping (mmap) a board that pulls information from an external
>data bus into my programs address space. The data is in a packed format. 
>Instead of using shifts and masks to extract the data I planed on using bit 
>fields. 

>The million dollar question is: Is it possible 
>to have a structure smaller than a full word, like a short? If so whats
>the declaration?


This is *heavily* system dependent. On SCO Xenix you can by
specifying with a pragma that the compiler pack a given
structure. Check the manual for your compiler. It might have
something similar.

But even if it does, I don't recommend doing this. There are
almost no guarantees about how bitfields behave. They certainly
aren't well enough controlled to make them appropriate for
modeling devices. Stick with shifts and masks.



-- 
Dave Eisen                               Sequoia Peripherals: (415) 967-5644
dkeisen@leland.Stanford.EDU              Home:                (415) 321-5154
       There's something in my library to offend everybody. 
          --- Washington Coalition Against Censorship
Newsgroups: comp.lang.c,comp.software-eng
From: mat@mole-end.matawan.nj.us
Subject: Re: Will we keep ignoring this productivity issue?
Summary: Pragmatics and immaturity
Organization: :
Date: Fri, 20 Nov 1992 17:58:50 GMT

In article <1ech41INN6jj@cs.ubc.ca>, ajackson@cs.ubc.ca (Ann Jackson) writes:
> In article <1992Nov13.211018.24360@novell.com>,
> Duane Murphy <damurphy@wc.novell.com> writes:
 ...
> |> I believe that we are not teaching programmers analysis before design.  
> |> We teach them syntax and pretend that this is analysis.  Analysis is real 
> |> and important.  How can you design a program that you cannot read!

> This reminds me of taking a course in educational theory last year.
> There's a widely-accepted hierarchy of cognitive skills that goes:
>        knowledge, ... analysis, synthesis, evaluation
 
> Educators believe that we always learn our way up this hierarchy from
> knowledge to evaluation. ... that in computer software, synthesis is
> normally taught before analysis and that analysis receives far less
> attention.  The instructor ... was aware of this, and also that computer
> science appears to be unique in this ... [have] the attractions of
> programming have distorted our educational policies[?]

I think it's natural given the immaturity of the field.  Y'know, Onology
Recapitulates Phylonogy, 'n all that.  The field itself began with
synthesis and got hung up on knowledge.  Educators are confusing deep
analysis of minimal data with a broad understanding rooted everwhere
in the context.  We've gotta' straighten things out, bit by bit.
-- 
 (This man's opinions are his own.)
 From mole-end				Mark Terribile

 mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ
Newsgroups: comp.lang.c
From: obright@obelix.gaul.csd.uwo.ca (BRYAN OBRIGHT)
Subject: Looking for B+ Tree Code in C
Reply-To: obright@obelix.gaul.csd.uwo.ca (BRYAN OBRIGHT)
Organization: University of Western Ontario
Date: Sat, 21 Nov 1992 23:35:43 GMT

If anyone has code for B+ Trees in C (preferably ANSI C), could you please
send it to me.  I don't really feel like coding this out.   I assume that
there is someone out there with this code. 

Mail me at :      obright@obelix.gaul.csd.uwo.ca

If you don't have the code but know a book with the code in it, a
reference would also be appreciated. 

Thanks,

Bryan Obright

University of Western Ontario, Canada
Newsgroups: comp.lang.c,comp.software-eng
From: wells@cdsmn.mn.org (Rich Wells)
Subject: Re: Will we keep ignoring this productivity issue?
Organization: Dicomed, Inc
X-Newsreader: TIN [version 1.1 PL6]
Date: Wed, 18 Nov 1992 16:51:40 GMT

mat@mole-end.matawan.nj.us wrote:
: 
: What the average programmer needs to know first is how to formulate a
: problem so that it is amenable to computer solution over the long term.
: This demands a simple, powerful theory that can directly abstract what is
: needed from the `physical' description.

So far, I agree.

:                                           I'm not saying that a programmer
: shouldn't understand the architecture of a digital computer, but that such
: an understanding will be an idealization, whose specifics cannot be applied
: to any particular hardware, and that it will have vanishing impact on 99%
: or more of his work.

This may be true for MIS types programming in 4GLs and the like,
but I find that a knowledge of the particular hardware one is
programming for is necessary for two reasons: (1) for the few
times that one needs to resort to assembly language to get the
needed performance, and (2) for debugging.  I have seen a
competent debugger who did not have intimate knowledge of the
hardware she was working on, nor have I ever seen a competent
programmer who was not also a good debugger.

(BTW: my opinion here comes from the two areas I work in on a day-
to-day basis: high-end, high performance photo retouch systems,
and embedded systems for controlling graphics output devices.  I'm
always interested in hearing from people in other application
areas as to how their perceptions on this sort of matter differs
from mine.)

:                    His vital skills are in applying the tools he is given
: to a problem, and to do that he must have a theory which provides him a
: penetrating understanding of the problem.

I'm not sure I understand this statement.  Could you clarify it
a little?  I'm not sure if you're talking about a general theory
of hardware, in which case I would argue that such a general
theory must be supplemented by a knowledge of the particular
h/w one is working with, or the basic theory behind the application
area, in which case the comment is a non-sequitur with which I
agree whole-heartedly.
-- 

Richard Wells  wells@cdsmn.mn.org  or  ...!tcnet!cdsmn!wells
Newsgroups: comp.lang.c
From: eager@eagercon.com (Michael J. Eager)
Subject: Re: & of array - what does ANSI specify for resulting value?
Reply-To: eager@eagercon.com
Organization: Eager Consulting
Date: Sun, 15 Nov 1992 18:44:22 GMT

In article 27456@dog.ee.lbl.gov, torek@horse.ee.lbl.gov (Chris Torek) writes:
>Others have posted the correct answer, but ...
>
>>>>[given] int foo[3]; [what is &foo?]
>
>In article <1992Nov13.205510.26280@eagercon.com> eager@eagercon.com writes:
>>ANSI sect 3.3.3.2 says "The operand of the unary & shall be ... an lvalue".
>
>So far so good...
>
>>foo is an rvalue,
>
>No, in ANSI terminology, `foo' is a `non-modifiable lvalue'.  (I prefer
>to say that foo is an `object', an object being something that lives in
>some kind of memory, and holds values.  This seems more self-explanatory
>than `lvalue is a contraction of left-value'.)
>
>>there is no object for the & operator to take the address of.
>
>`foo' becomes a value (`rvalue' in ANSI terminology) only in value
>contexts.  Unary `&' does not provide a value context, so `foo' stays
>an object.  Thus &foo is legal, and (given the declaration above) has
>type `pointer to array 3 of int', or `int (*)[3]'.
>
>Note that in Classic (pre-ANSI) C, the situation was slightly different.


Mea culpa.  I should know better.  Yes, an array is an non-modifiable lvalue.
I had forgotten that the array is not converted for &.


---
Michael J. Eager		Michael.Eager@eagercon.com
Eager Consulting		(415) 325-8077 
1960 Park Boulevard, Palo Alto, CA 94306-1141
From: ajmy@festival.ed.ac.uk (A Myles)
Newsgroups: comp.lang.c
Subject: Re: 2-D Arrays Problem Solved
Date: 20 Nov 92 09:24:35 GMT

Sorry I missed the start of this thread...

I had this problem recently, and noticed from scrutiny of the as code
that if you define the array using 2 doses of malloc() (one array
of pointers, say the rows, to arrays of whatever type you want
to store, which will be the columns)

(i.e. just like argv)

then the function will expand:

int	**foo;
/* whole buncha mallocs in here */
foo[bar][qux] = ... etc

correctly by evaluating the expression as (precedence rules)

(foo[bar])[qux]
^         ^
base of   element of 1d array
column

so you trade-off having the array scattered through memory for not
having to use array[one index * a size + another index] stuff, or defining
all bar one of the array dimensions - not great if you need dynamic
array sizing.
Remember the bounds!!!

Unfortunately, when passing such a beastie to a function, I found
I sometimes needed to use ***array as the arg. to allow for the fact that
the original 2-d array was defined as **array, and I wanted to
set up the array in the function so passed &array to it to allow
the base address to be loaded into array for use in the calling
function upon return. (arfle barfle gloop?)

this manifests itself as (in fn)

/* set base of whole shebang to pointer array */
*_base = (type**)malloc(ONEDIMENSION * sizeof(type*));
/* allocate pointers to data space */
(*_base)[element] = (type*)malloc(NEXTDIMENSION * sizeof(type));
/* fill data */
(*_base)[x][y] = the actual data;

it seems to work ok, but i can see it all ending in tears...

I haven't actually timed it, but i think the array of array method
may be faster since it is two look-ups rather than a multiply and
look-up for those on micro-coded-i-cant-multiply-integers-in-one-clock
machines, though the allocation will be slower (mallocs)

Andy.
Newsgroups: comp.lang.c
From: sca@gese.ge14.mdadv.gv.at (Petzi Schweda)
Subject: Re: The Correct Way To Write C if-Statements
Originator: sca@gese0n.ge14.mdadv.gv.at
Organization: MD-ADV, Vienna, Austria
Date: Fri, 20 Nov 1992 08:39:57 GMT


In article <aaronk.193.722052372@county.lmt.mn.org>, aaronk@county.lmt.mn.org (Aaron S. Kurland) writes:
!> What do you think of this style?
|> 
|> if (cond)
|> {
|>    statement1;
|> }
|> else
|> {
|>    statement2;
|> }
|> 
|> I always use the curlys even if there is only one statement in the block so 
|> if I ever need to add another (or a debug statement) I can do it easily.  I 
|> also like having the curly braces line up with the conditional statment.

think you'll end up a little bit messy when using this one inside blocks:

for (...)
    {
    if  (cond)
    {
        state;
    }
    else
    {
        state2;
    }
    }

too much paranthesis in this column, for my taste ...

go for it, Petzi
#####################################################
Petzi Schweda (sca@gese.ge14.mdadv.gv.at)
MD-ADV, Municipality of the City of Vienna, Austria
Newsgroups: comp.lang.c
From: alpha@waggen.twuug.com (Joe Wright)
Subject: Re: the abs() function in C
Organization: ALPHA, Box 68621, Va. Beach, VA 23455
X-Newsreader: TIN [version 1.1 PL6]
Date: Sun, 22 Nov 1992 02:23:57 GMT

Peter A. Bidian (pebi@aem.umn.edu) wrote:
: 
: Isn't abs(-2)=2 in C?
: I always get 0.
: 
: Confused!

This is almost always a macro like:

#define abs(x) ((x)>=0 ? (x) : -(x))

Some systems have abs(), fabs(), labs(), etc., as functions.
Look around.  Maybe you can simply declare it ..

	extern int abs();

-- 
Joe Wright  alpha@waggen.twuug.com  
"If we could only see the source code.."  (Dave Olson)
From: gowen@jade.tufts.edu (G. Lee Owen)
Newsgroups: comp.lang.c
Subject: Re: If statement question
Date: 23 Nov 92 04:50:38 GMT
Distribution: na
Organization: Tufts University - Medford, MA


	
	Sorry, took me a day extra to get this out, but here we go...

From ckkoo@magnus.acs.ohio-state.edu (Chee K Koo) on 20 Nov 92:
CKK> I am new to C programming, while i was doing a numerical analysis
CKK> program which uses many for loop
CKK> here is the loop looks like
CKK> for(i=1;i<=n;i++);
CKK> {
CKK> }
CKK> i put the ";" after the loop header, when the program is excuted, the
CKK> loop is skipped, however, it works fine when the ";" is removed.
	
  When you say 'for(i=1;i<=n;i++);' you are really telling the
compiler 'for(i=1;i<=n;i++) /* DO NOTHING */;'.  The for loop will
work on the (single) statement following it OR on the block following
it, where { and } mark off the block.  
  If you were writing a loop that would execute one statement, it
would be like this, right?
    for(i=1;i<=n;i++) printf("Hi #%d\n", i);
Notice how there is no ; between the end of the loop parens and the
printf statement.  Well, the same thing goes for a for loop with a
block following it.  Say you had to execute two statements, you would
put them in a block:
    for(i=1;i<=n;i++) 
        {
        printf("Hi ");
        printf("#%d\n", i);
	}
like such. The output of this would be (n == 5 here)
Hi 1
Hi 2
Hi 3
Hi 4
Hi 5
  Notice that, without the blocks, like this:
    for(i=1;i<=n;i++) 
        printf("Hi ");
        printf("#%d\n", i);
it will print "Hi " n times and then print "#i" where i has the same
value as n. If n equalled 5 you would get "Hi Hi Hi Hi Hi 5".
	
	I'm afraid I find this difficult to explain succinctly; I hope
these examples illustrate what you are seeing.  Perhaps you should dig
in your textbook a bit more...

CKK> I just want to find out why the compiler does not catch it during
CKK> compilation. It is compiled with UNIX gcc.
  Well, frankly, it's not the compiler's job.  More importantly,
neither would it always be correct to flag that.  Consider this:
  for (i=0; ((i<ARRAY_MAX)&&(array[i]!=42)); i++)  /* DO NOTHING */ ;
    printf("The Answer to Life is at array position %d\n", i);
  This fragment uses the loop to find the position in the array which
holds the value 42; the loop need not execute a statement, and the
side effect is that when the loop terminates, i has the value we are
interested in.

Hope this helps explain...


--
--Greg Owen
	gowen@forte.cs.tufts.edu, gowen@jade.tufts.edu
"C Spot. C Spot run. C Spot run without a core dump! Run, Spot, Run!"
From: map@remus.rutgers.edu (O. C.)
Newsgroups: comp.lang.c
Subject: But how did you get started?
Date: 21 Nov 92 21:03:30 GMT
Organization: Rutgers Univ., New Brunswick, N.J.


A few days back, someone posted a maybe real, maybe not post about
could the net help him keep his job by doing his work for him.  Many
of the people who responded were kind of sarcastic and what not, and
well they should be, but the thing that caught my eye in many of the
posts was the term "real world" vs academic world.  Here is some
background and then my questions.

Many times I go on interviews.  Everything starts out fine.  I can
talk about Unix and X windows and C.  I know what widget set I am
using.  I know the what is ANSI C vs Unix system calls.  I know about
the different flavors of unix.  I can answer all the questions put to
me, until we get to that last question, everything is going great.
Then they ask the deadly question: Where was your last job?  I tell
them that most of my programming has been in school.  I am half way
into my comp sci MS and have been using C for the last five years or
so.  I have done some programming on the side for my personal use and
for release to various newsgroups.  They then say,"But you've never
had a real job?"  They then act as if I had just called their mother a
whore. Well, thanks but not thanks.  We don't need any entry level
people. 

Here are my questions:

1. For all you "real world" programmers, what is wrong with my
academic background?  Some of the work I do is pretty involved.  I can
use a makefile.  I know how to comment my code.  Why is what I do here
so far from what you do?

2. Please feel free to mail me any personal stories about how you got
your "real world" experience.

3. If you have any old programs specs/code guidelines that your
employer would not mind you sending out, I would be grateful to see
the level I should be at vs. the level the "real world" seems to feel
I am at.

This is a serious post by a frustrated entry level person.  Any
comments as to what my background is lacking, good or bad, I would be
thankful for.

Also, if anyone reads this post and would be curious to give me a try,
I would be happy to show you what I can do.

Thanks in advance,

Michael A. Anderson
Newsgroups: comp.lang.c