HDTenEightyP/NetNews huggingface dataset:
From: eager@eagercon.com (Michael J. Eager)
Subject: Re: how to write C code so that redirection works
Reply-To: eager@eagercon.com
Organization: Eager Consulting
Date: Mon, 11 Jan 1993 06:17:58 GMT

In article 19456@mindlink.bc.ca, a7657@mindlink.bc.ca (Stephen H. Kawamoto) writes:
>i have a minor problem with C in that when i have a compiled file, FOO
>FOO <infile >outfile
>wont work. it 'hangs' and a ctrl-c or ctrl-break results in the outfile
>having more bytes in it (stuff from the uninitialized memory space i think).
>
>it's the CTOPAS.C source, which turns Pascal into Pascal-like pseudocode (not
>true Turbo Pascal in any case).
>
>here's the main where the problem might lie:
>
>>>
>>> void main()
>>> {
>>>    char c, *letter, word[100];
>>>    int wordlnth;
>>>
>>>    letter=word;
>>>    wordlnth=0;
>>>    while((c=getchar()) != EOF) {
>>>       if(isalpha(c)) letter[wordlnth++]=c;
>>>       else {
>>>          if(wordlnth>0) {            /* word ready to check
>>> */
>>>             letter[wordlnth]='\0';
>>>             wtest(word);             /* pass or replace it
>>> */
>>>             wordlnth=0;              /* reset index */
>>>          }
>>>          ctest(c);                   /* process following
>>> character */
>>>       }
>>>    }
>>> }   /* Note:  the last word in the file will be missed if it
>>> followed by EOF with no intervening nonalphanumeric
>>> characters.  This is not a problem for Pascal or C source
>>> files.  */


Try changing the declaration of c from char to int.  Most implementations
of getchar return a char sized value for the 256 character values which can fit
in a byte, but the EOF value is outside this range (often -1).  When you save
it in char c, it gets truncated and is not recognized as the end of file.
 

---
Michael J. Eager		Michael.Eager@eagercon.com
Eager Consulting		(415) 325-8077 
1960 Park Boulevard, Palo Alto, CA 94306-1141
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: C -> fortran ?
Date: 4 Jan 93 19:54:29 GMT
Organization: negligable

The closest thing to that that I know of is something called "RATFOR"
that was developed (I think) by one of the guys responsible for C.  It
stands for "RATional FORtran" and provides a lot of the same syntax
as C code.  It is NOT C to Fortran, but may come close enough to be
of use.  Unfortunately I have no idea where you should go to look
for it.  Perhaps someone else has more info?

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Between the silence of the mountains	|
and the crashing of the sea 		|	-Richard Hartman	
there lies a land I once lived in	|	hartman@uLogic.COM
and she's waiting there for me.		|
From: linden@positive.Eng.Sun.COM (Peter van der Linden)
Newsgroups: comp.lang.c
Subject: Re: Moving from Pascal to C
Date: 10 Jan 1993 00:01:35 GMT
Organization: Sun
Distribution: world
NNTP-Posting-Host: positive


From: raph@panache.demon.co.uk (Raphael Mankin)
> IMHO the only thing one can say about pointer arithmetic is DON'T.

> If your pointer points to an array, use subscripting. 
> If your pointer is to a single item, then the only thing you should do with it
>                                       is to follow it (dereference).

And what if your pointer points to neither an array, nor a single item?
But to say, a block of dynamically-malloc'd memory?

The advice above is not too surprising, coming from someone who prefers
to hire programmers with "a degree in English or History or Physics, or 
anything except CS."

Maybe if you hired a few CS grad's, you'd know more about these other corners of C.

Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.misc
From: wieck@jwminhh.hanse.de (Jan Wieck)
Subject: Re: How to turn PC speaker off?
Organization: Private Site under Mach386
X-Newsreader: Tin 1.1 PL4
Date: Fri, 8 Jan 1993 00:48:49 GMT

rs@cmie.ernet.in (Rajappa Iyer) writes:
: wieck@jwminhh.hanse.de (Jan Wieck) writes:
: : cschang@hamlet.umd.edu (C. S. Chang) writes:
: : : Is there any way to turn the PC speaker off so that there will be no
: : : beeps if a certain function call failed.  I do not have access to this
: : : particular function call which beeps at failure.  So I am looking for
: : : a way to prevent the PC from generating some beeping noise.
: : 
: : Oh, you wanted a solution for PC-DOS? Well, also possible, cut the
: : wire (this is no joke - it's the only way under PC-DOS).
: 
: Well, yes, this is the only way to do it for programs which control
: the sound chip directly and / or write to the speaker port. But if you
: are interested in cutting out plain vanilla beeps from plain vanilla
: apps (which are likely to be using a dos / bios call to write ASCII 7 for
: beep) then you *can* intercept the bios video interrupt and disable the
: beep.

Normally (all the user's in our office) someone want's to turn off
the speaker to play games. Most games have a turn-speaker-off-feature
(and some a boss-is-coming-hotkey) today. But ALL games directly
write to the speaker port.

Just interested - let us know for what reason do you need this feature,
Mr./Mrs. Chang?


Until later, Jan

-- 
# Any language keeps its own misunderstandings; #
# why shouldn't programming languages do?       #
#                                               #
#            wieck@jwminhh.hanse.de (Jan Wieck) #
Newsgroups: comp.lang.c,comp.lang.c++
From: vpham@cs.ulowell.edu (vinh)
Subject: Re: C/C++ Speed
Organization: University of Massachusetts at Lowell Computer Science
Distribution: usa
Date: Mon, 11 Jan 1993 03:20:23 GMT

In article <1iq4jj$5fr@agate.berkeley.edu> jbuck@forney.berkeley.edu (Joe Buck) writes:
>In article <1ipsk5INNf5m@aludra.usc.edu> dliao@aludra.usc.edu (David Liao) writes:
>C++ programmers typically tackle larger problems than C programmers;
to me, the most complex piece of software is an OS; and so far
i haven't seen a  successful commercial OS written in C++.

Xref: sparky comp.lang.c:19520 comp.lang.pascal:8025 comp.lang.prolog:2348
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.c,comp.lang.pascal,comp.lang.prolog
Subject: Re: Assessing a language
Date: 11 Jan 93 06:28:24 GMT
Followup-To: comp.lang.prolog
Organization: Comp Sci, RMIT, Melbourne, Australia

In article <nharvey.726285484@probitas>, nharvey@probitas.cs.utas.edu.au (Nicole Harvey) writes:
> hi,
>    I am involved in assessing a language. Does anyone know of a standard
> set of problems that I could use to judge the languages compabilities?
>    Can anyone think of a problem that represents a real need in a language?
> For example, we have tested it for the eight queens problem to show that 
> it can do state space searches. We have also made sure it can generate the 
> Fibonacci numbers. Can you think of any other well known problems?

I note that this is posted to comp.lang. c, pascal, prolog.
Obviously, to be fair to Prolog, you should include something like
    - a parser for a large fragment of a human language; Chat-80 is
      available for research use and you might try to adapt that grammar
    - a nonlinear planner
    - a polynomial manipulation package (got to have SOMETHING C can do...)
and in order to be fair to C, you should include something like 
    - the X window system
and in order to be fair to Pascal, a Pascal compiler.

If you expect to get anything meaningful out of a handful of toy problems,
forget it.  The results would be a far worse joke than my first paragraph.
ANY programming language can do state space searches, and how hard it is
depends largely on how much of a library you have, not on the syntax of
the language.  ANY programming language (even BASIC restricted to 26
scalar variables) can compute Fibonacci numbers.  I can solve a set of
linear equations in Prolog in two lines (one line to load the appropriate
library package and one line to call the appropriate routine).  The same is
true in TURBO Pascal, or Fortran, or C.  

As for Fibonacci numbers, consider the following lazy functional definition:
    let fib = 1 : 1 : map2 (+) fib (tl fib);
Hard to beat that.  It has been argued that lazy evaluation is extremely
important, yet there are no lazy languages in your list, not even Scheme
with "streams" (see Abelson & Sussman, Structure & Interpretation of
Computer Programs).
From: lord@tradent.wimsey.bc.ca (Jason Cooper)
Newsgroups: comp.lang.c
Subject: ** Ack!  Help again! **
Date: Sun, 03 Jan 93 14:07:07 PST
Organization: TradeNET International Trade Corp.

Well, I've solved the previous problem I posted.  It wasn't anything 
difficult, really.  I am now having trouble with console input.  Every 
time I use scanf or gets, and I ask for more than one input of a string 
in a row, like this:

gets(string1)
gets(string2)

or however that works (the point being they are seperate lines), C will 
skip some of the inputs for apparently no reason at all.  Could someboy 
help me out here (oops, someBODY)?  I can't seem to find a method of 
inputting strings that won't go and do that to me.

                                                Jason Cooper
From: jos@and.nl (Jos Horsmeier)
Newsgroups: comp.lang.c
Subject: Re: How can you evaluate an arbitrary function?
Date: 7 Jan 93 09:16:09 GMT
Organization: AND Software BV Rotterdam

In article <1993Jan6.202453.8630@news.tufts.edu> slahiri@jade.tufts.edu (Sandip Lahiri) writes:
|Suppose you have to write a program which would accept any arbitrary 
|function f(x) and calculate its values for x = ... . The program has 
|to be written in C. How would you go about it ? [ ... ]

Two approaches come to mind:

- Use yacc and lex (or equivalent tools) to generate the parser and 
  lexical analyzer for you; 

- Write your own parser and lexical analyzer.

The grammar for this particular language (well formed expressions) is
not too difficult to construct. Many textbooks give skeletons of such
a grammar (e.g. the Dragon Book) If you want to build your own parser,
may I suggest to construct a right recursive grammar first (or more
specifically: an LL(1) grammar) because the derivation of the actual
C code from it is very easy to do. A short example may clarify things
a bit. The following three rules:

E	= T { [+-] E }
T	= F { [*/] T }
F	= x | c | f ( E ) | ( E ) | - F

make up a fairly complete syntax for arithmetic expressions. (f = any
function name, x = the function parameter, c = any constant) These rules
can directly be translated to C as follows:

double E() {

	double Result = T();

	for(;;)
		switch (Token()) {
			case '+': Result+= T(); break;
			case '-': Result-= T(); break;
			default : PushBackToken();
				  return Result;
		}
	return Result;
}


double T() {

	double Result = F();

	for(;;)
		switch (Token()) {
			case '*': Result+= F(); break;
			case '/': Result-= F(); break;
			default : PushBackToken();
				  return Result;
		}
	return Result;
}

double F() {

	double Result;

	switch (Token()) {
		case 'x': return GetParValue();
		case 'c': return GetConstValue();
		case '-': return -F();
		case '(': Result= E();
			  if (token() != ')') {
				perror("')' expected");
				abort();
			  }
		case 'f': if (token() != ')') {
				perror("'(' expected");
				abort();
			  }
			  Result= E();
			  if (token() != ')') {
				perror("')' expected");
				abort();
			  }
			  return ApplyFunc(Result);
		default : perror("Syntax error");
			  abort();
	}
}

Well, I hope you get the picture ... Recursive descent parsing is not
the difficult part. Building a lexical analyzer can be a tedious job:
it not only has to recognize floating point constants and function
names (and parentheses, operators etc.) but it also has to transform
the string representation of those constants into an internal repre-
sentation (double type) It's much more convenient to use lex (or a
similar tool) for that. 

I hope this helps a bit. Kind regards,

Jos aka jos@and.nl
Newsgroups: comp.lang.c
From: mark@ocsmd.ocs.com (Mark Wilson)
Subject: Re: A different C puzzle
Organization: Online Computer Systems, Inc.
X-Newsreader: Tin 1.1 PL5
Date: Tue, 5 Jan 1993 12:55:46 GMT

Alun (champion@cch.coventry.ac.uk) wrote:
: In article <1992Dec23.185348.19343@sharebase.com> keith@torme.sharebase.com (Keith Chambless) writes:
: ~In article <1992Dec23.092712.2408@sq.sq.com> msb@sq.sq.com (Mark Brader) writes:
: ~>> > Write a [C] program that uses every valid character exactly once.
: ~>> I should think it would be rather difficult to use only one " ...
: ~
: ~Best I could come up with is:
: ~
: ~#
: ~
: ~main()
: ~{
: ~	double *ABCDEFGHIJKLMNOPQRSTUVWXYZ[],
: ~		   c_fghjkpqrstvwxyz = -!9 + 8.0 / 7 > 6 < 5 % 4 ? 3 : 2 & 1;
: ~}
: ~
: ~
: ~missing are ' " \
: 
: What about ^ | ~
: Also it doesn't seem to compile - it complains about no size for the array.
: 
: #
: double *ABCDEFGHIJKLMNOPQRSTUVWXYZ[],
:        c_fghjkpqrstvwxyz = -!9 ^ +8. / 7 > 6 < 5 % 4 ? 3 : 2 & 1 | ~0;
: 
: main()
: { }
: 
: Sticking the double as global does compile with gcc -ansi and I have added the
: other operators.
: 
: I can't see any way of gettting the ' " \ into the program.
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: 
:   -Alun
:
   
Wouldn't this work?:

#
double *ABCDEFGHIJKLMNOPQRSTUVWXYZ[],
       c_fghjkpqrstvwxyz = \
-!9 ^ +8. / 7 > 6 < 5 % 4 ? 3 : 2 & 1 | ~0;

main()
{ }

=============
It compiles under gcc.  (Would it be OK to indent the "-9!..." line, or
would that extra TAB be disallowed?)
--
-------------------------------------------------------------------------------
Mark Wilson, Online Computer Systems.  1-800-922-9204 or 1-301-601-2215
(Try email address mark@wilson.ocs.com....)
This file .disclaims everything signed with my .signature, I .mean it!
-------------------------------------------------------------------------------
Newsgroups: comp.lang.c
From: kelson@ais.org (David Lewis)
Subject: Borland C++ 3.0 and fixed stack size.
Organization: UMCC
Date: Sun, 10 Jan 1993 04:20:54 GMT



  I have TurboC++ 3.0, and Autocad 12.  I was attempting to write a 
real mode program to run inside of Autocad and everything worked
great except for the fact of if you shelled out of autocad, autocad
would crash.  According to the docs you have to make the programs
memory layout the same as if you were writing a TSR in order for it
NOT to crash (fixed stack size and dynamically allocated heap on top
of the program).  I am not really sure how to do this... can anyone
give any insight?

  Thanks
    --David

Newsgroups: comp.lang.c
From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
Subject: Re: How to read without echo.
Date: Tue, 5 Jan 1993 16:25:45 GMT
Organization: TH Darmstadt

In article <1993Jan4.182945@rbg.informatik.th-darmstadt.de>, misar@rbg.informatik.th-darmstadt.de (walter misar) writes:
> #include <sgtty.h>
> main()
> { struct sgttyb *ttyio;
>   ...
>   gtty(0,ttyio);
>   (ttyio->sg_flags)&=(~ECHO);	/* echo off	*/
>   stty(0,ttyio);   
>   ...   /* read without echo */
>   (ttyio->sg_flags)|=(ECHO);	/* echo on	*/
>   stty(0,ttyio);
>   .....
> }

Oops, there was an error (the pointer of ttyio never gets initialized).
Strange enough, it worked for me.
This could be fixed as follows:

#include <sgtty.h>
main()
{ struct sgttyb ttyio;
 ...
 gtty(0,&ttyio);
 (ttyio.sg_flags)&=(~ECHO);	/* echo off	*/
 stty(0,&ttyio);   
 ...   /* read without echo */
 (ttyio.sg_flags)|=(ECHO);	/* echo on	*/
 stty(0,&ttyio);
 .....
}  

However a more portable way would be to use ioctl:

#include <sys/ioctl.h>
#include <termio.h>
/* Hm, my manpage says to use termios instead, but that didn't work (HPUX8.0) */

main()
{ struct termio ttyio;

  ioctl(0,TCGETA,&ttyio);
  ttyio.c_lflag &= ~ECHO;
  ioctl(0,TCSETA,&ttyio);
   ... /* read without echo */
  ttyio.c_lflag |= ECHO;
  ioctl(0,TCSETA,&ttyio);
  ...
}

Thanks to the people, who told me about the error.

-- 
Walter Misar                        It is impossible to enjoy idling thoroughly
misar@rbg.informatik.th-darmstadt.de       unless one has plenty of work to do.
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: Program to convert .EXE to a "C" source file?  I really need one!!
Date: 4 Jan 93 19:51:42 GMT
Organization: negligable

In article <C0B6x5.DA6@ulowell.ulowell.edu> mbrousse@cs.ulowell.edu (Marc Brousseau) writes:
>>I'd prefer a program that generates the RCS or SCCS archives the program was 
>>developed in, plus a makefile.  Architectural and design documents would be 
>>nice too.

I'd like one of these too.  Which FTP site is it on?

>I want a printer that will run in reverse, taking in a document, and
>converting it to a word processor file. Word for Windows out of a
>newspaper would be nize.

Darn.  Reality.  Bummer.

(*sigh*) It's called a "scanner" with OCR software.  Call CompUSA (or
your local computer superstore) to see what they've got.  You may not
get font point sizeing though....

Now can we get back to fantasy again?

		-Richard Hartman
		hartman@ulogic.COM

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
"Fosters!  It's Australian for beer, mate!"
From: wilson%inf.UFRGS.BR@UICVM.UIC.EDU (Wilson Roberto Afonso)
Newsgroups: comp.lang.c
Subject: Re: Problem with string processing.
Date: 7 Jan 1993 13:05:58 -0600
Organization: UTexas Mail-to-News Gateway
NNTP-Posting-Host: cs.utexas.edu


>>Assuming a large enough string for the append, and low-high byte ordering,
>>would this work?
>>
>>strcat(str,(char *)&ch);
>>
>
>Well, it would work *sometimes*.  Remember that strcat() expects two pointers
>to ZERO-TERMINATED strings. [...]

I think that the point here is "low-high byte ordering".  If we have eight-bit-
-chars, AND low-high ordering, wouldn't surely be a zero after the char ?
I think that I am probably wrong, but that's what I thought he was talking
about.

-Wilson  (wilson@inf.ufrgs.br)
  ________________________________________________________________________
 |                                               |                        |_
 | Wilson Roberto Afonso                         |     E-adresses :       | |
 | Instituto de Informatica - UFRGS              |                        | |
 | Inteligencia Artificial - Bancos de Dados     | wilson@inf.ufrgs.br    | |
 | Porto Alegre  -  RS  -  Brasil                | wilson@vortex.ufrgs.br | |
 | "Imagination is more important than knowledge"|                        | |
 |                        Albert Einstein        |                        | |
 |________________________________________________________________________| |
   |________________________________________________________________________|




----- End Included Message -----

Newsgroups: comp.lang.c
From: gupta@adtaz.sps.mot.com (Rajesh Gupta)
Subject: Linker problem
Reply-To: gupta@adtaz.sps.mot.com
Organization: Motorola, Inc.
Date: Thu, 7 Jan 1993 16:46:28 GMT

I am creating a debuggable executable by statically linking in a few
archives. However, the linker fails to recognize the symbols in one
of the ar libraries ????

I can't see where the problem could be. Any clues will be appreciated.

--- Rajesh

************************************************************************
Rajesh Gupta                                gupta@ssdt-tempe.sps.mot.com
Motorola, Inc.
Tel: 602 897 3991                           FAX: 602 897 3518
************************************************************************
From: slahiri@jade.tufts.edu (Sandip Lahiri)
Newsgroups: comp.lang.c
Subject: How can you evaluate an arbitrary function?
Date: 6 Jan 93 20:24:53 GMT
Organization: Tufts University - Medford, MA

Suppose you have to write a program which would accept any arbitrary 
function f(x) and calculate its values for x = ... . The program has 
to be written in C. How would you go about it ? Note, common lisp 
does have the eval primitive and this task is considerably easier
if the program is written in lisp. Should you write a parser first to
check the input ? Remember we can have a function nested to any 
arbitrary depth e.g. f(x) = tan(tanx + sin(cos(sinx + x^2)) + 5).
Any help/pointers most welcome.
Thanx in advance.

Sandip
From: tlp00@ras.amdahl.com (Tibor Polgar)
Newsgroups: comp.lang.c
Subject: Protoize
Date: 11 Jan 93 23:19:50 GMT
Reply-To: tlp00@ras.amdahl.com
Organization: Amdahl Corporation, Sunnyvale CA

I'm looking for a program called "protoize".  It is a filter that generate function
prototypes given a C source file.   Any info would be apprecated.

-------------------------------------------------------------------------------
| Tibor L. Polgar    |  (408) 746-8649     | tlp00@climb.ras.amdahl.com
| Amdahl Corporation
| 1250 East Arques Avenue (M/S 281)
| P.O. Box 3470
| Sunnyvale, CA 94088-3470
------------------------------------------------------------------------------
Newsgroups: comp.lang.c
From: steve@taumet.com (Steve Clamage)
Subject: Re: Problem with Turbo-C: calculating with pointers 
Organization: TauMetric Corporation
Date: Sat, 9 Jan 1993 16:19:34 GMT

raph@panache.demon.co.uk (Raphael mankin) writes:

>>long size;
>>
>>size=71800;
>      ^^^^^
>make this 71800L and it will work. This compiler like many others treats integer
>cosntants as 16-bit ints. 61800-65536 == 6264.

This had better not make any difference, and in fact makes no difference
with Borland C.

The rule in C is that a decimal integer literal is type int if the value
will fit in an int, and type long otherwise.  Thus, 71800 and 71800L have
exactly the same value and type.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
From: sundar@billberry.ai.mit.edu (Sundar Narasimhan)
Newsgroups: comp.lang.c
Subject: compilers and code generation (struct vs. array)
Date: 7 Jan 93 16:16:31 GMT
Reply-To: sundar@ai.mit.edu
Organization: MIT Artificial Intelligence Laboratory
NNTP-Posting-Host: billberry.ai.mit.edu

Let's say a point is defined as
	struct point { 
		double x, y;
        }
or as
typedef double point[2];

I'm interested in the usual operation on points. (i.e. 
additions, subtractions, multiplications, co-ordinate access,
and transformations -- i.e. multiplication by a 2x2 or 3x3 matrix 
which again can be represented as an array or struct).

Now let's look at one of these operations in detail:

point_add(p1, p2, p3)
struct point *p1, *p2, *p3;
{
	p3->x = p1->x + p2->x;	
	p3->y = p1->y + p2->y;	
}

or as
point_add(p1, p2, p3)
double *p1, *p2, *p3;
{
	p3[0] = p1[0] + p2[0];
	p3[1] = p1[1] + p2[1];
}

One can see how to do the other operations, similarly. Obviously for
speed, these can be made into macros.

Do compilers usually generate the same code in both the above
cases? (My experience has been that with the optimizers turned
on Sun CC and GCC do this, but I'd like to know if this is something
I can rely on -- Without the -O switch, of course, the code generated
can be wildly different in the various cases).

I've tried benchmarking the two methods under real conditions, however,
and the evidence has been in-conclusive. (i.e. I've tried it on sparcs
configured in various ways, and have been surprised to find that on some
machines one method consistently outperforms the other while neither
is the best in all configurations and I haven't been able to discern
why this is the case.) Has anyone else tried this or something
similar that I could learn from?
Newsgroups: comp.lang.c