HDTenEightyP/NetNews huggingface dataset:
From: dfuller@portal.hq.videocart.com (Dave Fuller)
Subject: Re: passing variables to system() ?
Organization: VideOcart Inc.
X-Newsreader: Tin 1.1 PL3
Date: Tue, 12 Jan 1993 20:45:43 GMT

apwhite@unix1.tcd.ie (Andrew White) writes:
: Hi There,
:   I have a C program written in which I want to call another program (written in
: awk), passing that program a variable -ie (awkprog x=variable filename) is there
: a way I can do this with system() or is it a bit more complicated than that??
: 
: BTW Yes, I do need to call the program , I am not going to use C for field 
: matching etc. 
: 
: 
: Thanks
: Andrew.
: 

  Create the command ahead of time, then pass to system.

char xvar[20];      /* these are all arbitrary sizes, use a better method */
char file[20];
char syscall[50];  

strcpy(file, "testfile");
strcpy(xvar, "find");  /* i assume that you want to pass a command line
                          that looks like   
                          awkprog text file
                       */
/*  file and xvar can be any char pointer, i just set them up this way
    for an example. All you are probably concerned with are the next 2 lines
*/

sprintf(syscall, "awkprog %s %s", xvar, file);
system(syscall);   /*  you should always check return values from system */   

That should do it.

Dave Fuller
dfuller@portal.hq.videocart.com

Newsgroups: comp.lang.c
From: raph@panache.demon.co.uk (Raphael mankin)
Subject: Re: Moving from Pascal to C, Help please!!!!!! 
Distribution: world
Organization: Solvfield Ltd.
Reply-To: raph@panache.demon.co.uk
X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
Date: Fri, 8 Jan 1993 16:32:34 +0000

In article <4293@dozo.and.nl> jos@and.nl writes:

>
>Another way to approach pointer arithmetic is first to convert the
>pointer(s) to character pointer(s): [ ... ] For pointer subtracion,
>the result of the difference between the character pointers is 
>similarly divided by the size of the object originally pointed to.
>

IMHO the only thing one can say about pointer arithmetic is DON'T.
Regardless of what K&R or the standard say about its legality, tinkering
with pointers is one of the surest ways of getting into trouble. 30 years
of programming, in more languages than most readers of this group have even
heard of, has led me to this position.

If your pointer points to an array, use subscripting. Let the compiler's
optimiser work out whether there are really better ways of doing the job.

If your pointer is to a single item, then the only thing you should do with it
is to follow it (dereference).
-- 
--------------
Raphael Mankin			Nil taurus excretum
From: eaeu209@orion.oac.uci.edu (Rodney G. Ramos)
Subject: Re: **BOOKS TO LEARN C: SUGGESTIONS NEEDED**
Newsgroups: comp.lang.c
Organization: University of California, Irvine
Distribution: usa
Date: 9 Jan 93 09:31:48 GMT
Followup-To: comp.lang.c

In article <eaeu209-090193013620@714-725-3177.nts.uci.edu>,
eaeu209@orion.oac.uci.edu (Rodney G. Ramos) wrote:
> 
> I've recently been interested in learning C. Can anyone suggest a good book
> to get me started?
> 
> I already know Pascal, so it's important that I find a book that does not
> assume the reader has no knowledge or experience with programming.
> 
> Any suggestions would be much appreciated. I would also like to compile
> a list of the responses for future reference for others.
> 
> Please e-mail if possible.
> Rodney

Oops, my fault. Definitely screwed up here. I forgot to give my
proper email address. Here it is:

eaeu209@orion.oac.uci.edu
Newsgroups: comp.lang.c
From: cpcahil@vti.com (Conor P. Cahill)
Subject: Re: Question on malloc
Organization: Virtual Technologies Inc.
Date: Fri, 8 Jan 1993 12:04:11 GMT

In article <1993Jan8.010231.14608@news.uiowa.edu>, hari@blackmail.eng.uiowa.edu (Hari Vattikota) writes:
> Hi,
> 
> 	subroutine.Irrespective of the amount of malloc I do before calling
> 	this subroutine it always crashes at the first malloc in the
> 	subroutine.I am executing the program on an HP Apollo series 400
> 	machine and the error message is "Conflicting versions of malloc

What is the link command used to generate the executable?  It sounds like 
you somehow have gotten two malloc libraries to link into your executable
(which should generate a duplicate symbol message from the loader) or 
you are doing your an sbrk() in your code and the standard malloc library
doesn't like other people doing an sbrk().



-- 
*** SENTINEL(tm) The ultimate Debugging Environment - email for more info ***

Conor P. Cahill              (703)430-9247            cpcahil@virtech.vti.com
Virtual Technologies, Inc.  46030 Manekin Plaza          Dulles, VA 20166
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c
Subject: Re: Program to convert .EXE to a "C" source file?  I really need one!!
Date: 7 Jan 93 23:55:16 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

/* Use: bin2c <infile.exe >outfile.c
 *
 * Note: this includes a few UN*Xisms, but I'm sure equivalent calls can
 *   be substituted on other systems.  Also, you should probably generate 	
 *   random names (particularly under multitasking systems) instead of
 *   relying on "/tmp/foo.exe" to be non-existant.
 */

#include <stdio.h>

char *s1[] = {
  "#include <stdio.h>",
  "",
  "int bytes[] = {",
  NULL
  } ;

char *s2[] = {
  "-1 } ;",
  "",
  "int main() {",
  "  int i ;",
  "  FILE *f = fopen(\"/tmp/foo.exe\",\"w\") ;",
  "  if( f == NULL ) {",
  "    fprintf( stderr, \"FATAL ERROR: can't open temp file\\n\" ) ; exit(1) ;"
  "    }",
  "  for( i = 0 ; bytes[i] >= 0 ; i++ )",
  "    fputc( bytes[i], f ) ;",
  "  fclose(f) ;",
  "  system( \"chmod +x /tmp/foo.exe\" ) ;",
  "  system( \"/tmp/foo.exe\" ) ;",
  "  system( \"rm /tmp/foo.exe\" ) ;"
  "  return 0 ;",
  "  }",
  NULL } ;

void ps( char *s[] ) {
  int i ;
  for( i = 0 ; s[i] != NULL ; i++ ) puts( s[i] ) ;
  }

int main() {

  int c, nc = 0 ;

  ps( s1 ) ;

  while( (c = getchar()) != EOF ) {
    if( nc++ % 16 == 0 ) putchar( '\n' ) ;
    printf( "%3d, ", c ) ;
    }

  ps( s2 ) ;
  }

-- 
[An intertialess drive] is not probable at all, at least in any extrapolation
of present-day science.  But as far as I can determine, it cannot be proved
absolutely impossible, and that is enough for me.        -E. E. "Doc" Smith
Newsgroups: comp.lang.c,comp.lang.pascal
From: cshaver@informix.com (Craig Shaver)
Newsgroups: comp.lang.c,comp.lang.c++
Subject: Re: C/C++ Speed
Date: 11 Jan 93 21:00:15 GMT
Distribution: usa
Organization: Informix Software, Inc.

In article <1993Jan11.161017.16545@taumet.com> mike@taumet.com (Mike Ball) writes:
>vpham@cs.ulowell.edu (vinh) writes:
>
>>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++.
>
>Most of which just shows inexperience.  Operating systems are far from
>the most complex software out there.
>
>Also, all successful commercial OS's were written decades ago, since it
>takes that long to become a success.
>-- 
>Michael S. Ball (mike@taumet.com)
>TauMetric Corporation

A few years ago there was a rumour that the Sun/ATT DeathStar :') alliance was
going to rewrite UNIX using OOPS and C++.  Does anyone know what happened to
that idea?

I know of a few projects that won't be using C++ because of safety and 
portability concerns!  

Why is c++ supposed to be safer than c?

-- 
Craig Shaver  (cshaver@informix.com for now) (415)390-0654 (415)926-6407
Productivity Group POB 60458 Sunnyvale, CA  94088
Newsgroups: comp.lang.c
From: bibhas@pico.engr.mun.ca (Bibhas Bhattacharya)
Subject: extern: interesting case...
Keywords: extern
Organization: Memorial University of Newfoundland
Date: Wed, 6 Jan 1993 17:30:39 GMT

When I declare:
extern char line[];
for the variable "line" which was defined in another file as:
char line[80];
everything works fine. But when I do:
extern char *line;
the program dumps core. I can't figure out the difference, especially when
extern declaration is not supposed to reserve any memory or anything. When
I looked up K&R, the correct declaration would be: extern char line[];.

Can anyone please clarify the case.
Thanks.
Bibhas
--
	+==========================+=========================+
	| login name: DR. Jackyl   |  In real life: Mr. Hyde.|
	+==========================+=========================+
		          bibhas@pico.engr.mun.ca  
Newsgroups: comp.lang.c
From: s1110238@giaeb.cc.monash.edu.au (Lee Hollingworth)
Subject: Re: C if else statements HELP
Organization: Monash University, Melb., Australia.
Date: Sat, 9 Jan 1993 10:25:08 GMT

ctoth@magnus.acs.ohio-state.edu (Christopher M Toth) writes:

>	Hi! I just started learning C and have run into problems with
>'if' and'else' statements. I have a program that I am *trying* to write. The
>basic format is:

>	printf ("which do you choose?");
>	scanf("%d", &n);
>	choice#1
>	choice#2
>	choice#3
>	choice#4

>	if choice #1
>		printf.....
>	if choice #2
>		printf.....
>	if choice #3
>		printf.....
>	if choice #4
>		printf.....

>	I want the program to goto the approiate section when the user
>inputs either 1,2,3,or 4. ANy help would be greatly and mostly appreciated! :)

>Thanks!

Try using a switch statement...

    printf("Enter choice (1-4): ");
    if (scanf("%d", &n) != 0) {
        switch (n) {
            case 1:
                /* do stuff for this choice */
                break;
            case 2:
                /* do stuff for this choice */
                break;
            case 3:
                /* do stuff for this choice */
                break;
            case 4:
                /* do stuff for this choice */
                break;
            default:
                /* invalid input! */
                break;
        }
    }
From: dkeisen@leland.Stanford.EDU (Dave Eisen)
Subject: Re: Any hope for me..? 
Organization: Sequoia Peripherals, Inc.
Date: Thu, 7 Jan 93 17:37:28 GMT

In article <C0Hty1.DvH@netnews.jhuapl.edu> bandy@netnews.jhuapl.edu (Mike Bandy) writes:

>Why is it that they'll let anyone program, but let a non-EE major (for 
>example) apply for an EE job, and he's eliminated from consideration 
>immediately?
>

Because Computer Science is not yet nearly as mature a
discipline as Electrical Engineering is. Yes, it is 
important to have knowledge of various types of data
structures and it is important to understand how to
do a good design when programming and there are lots
of other things that one learns while getting a CS
degree that are important to know to be a good programmer.

But one can pick them up after one begins programming,
and most of them are pretty intuitive to someone bright
just entering the field. A bright mathematician or philosopher
or physicist is likely to be a good programmer after working
as a programmer for 6 months to a year.

On the other hand, if you threw me into a job where I had to 
serious digital design, I would be hopelessly lost. There's
just too much one needs to know before he even gets started.




-- 
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
From: fred@genesis.demon.co.uk (Lawrence Kirby)
Subject: Re: Fopening a text file 
Distribution: world
Organization: BT
X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
Date: Tue, 5 Jan 1993 12:34:12 +0000

In article <1993Jan5.015937.19270@vpnet.chi.il.us> mox@vpnet.chi.il.us writes:

>I'm having some problems with a program that I wrote for this computer
>which is running a sys V unix operating system.  My problem is with
>fopen.  When I try do a fopen("filename", "rt"); it opens the file as a
>binary.  If I drop the t, is still creates a binary file.  So how do I
>make fopen create a straight text file?
>

In Unix there is no distinction between a binary and a text file. The problem
in DOS is that the line terminator is CR-LF whereas in C it is just LF. So C's
file I/O system has to perform translation for text files. Unix, like C, uses
just LF as a line terminator so no translation is required. Remember C was
created to write Unix.

-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Newsgroups: comp.lang.c
Subject: Recusion
From: lindstrom@acs.harding.edu
Date: 7 Jan 93 09:48:47 -0500
Reply-To: lindstrom@acs.harding.edu
Organization: Harding University

Hello all-
  I am attempting to write a recusive C routine and 
am seeing the following error at compile: "can't size
function."  Hmmm. Any thoughts ? I am running a Sun
SPARC IPC with SunOS 4.1.2 and the vanilla compiler.
Please e-mail me as I do not read this group everyday.

  Thanks-
    Greg Lindstrom
    Harding University
    glind@sun1.hu.edu
From: rogers@calamari.hi.com (Andrew Rogers)
Newsgroups: comp.lang.c
Subject: Re: Problem with string processing.
Date: 5 Jan 1993 23:26:08 -0000
Organization: Hitachi Computer Products, OSSD division
NNTP-Posting-Host: calamari.hi.com

In article <Ts3TwB1w165w@wozzle.linet.org> alane@wozzle.linet.org (J. Alan Eldridge) writes:
>>         char tmp[2] = {0};
>>  
>>         *tmp = ch;
>>         strcat(str, tmp);
>
>tmp[0] has a 0 in it but tmp[1] is undefined. You are not creating
>a nul-terminated string here.

tmp[1] most certainly does have a 0 in it; if the initialization list for
an array contains fewer elements than the array itself, then the remaining
array elements are initialized to 0.  Check the ANSI spec, or the relevant
section in K&R.

AWR
Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.misc
From: sj@cs.brown.edu (Shuang Ji)
Subject: Re: How to turn PC speaker off?
Organization: Brown Computer Science Dept.
Date: Fri, 8 Jan 1993 19:52:56 GMT

In article <1993Jan8.004849.1660@jwminhh.hanse.de>, wieck@jwminhh.hanse.de (Jan Wieck) writes:
|> 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) #

It's practically impossible to turn off the speaker. But you can write
a TSR program which will intercept the clock interrupt and repeatedly
send CLOSE commands to the port register controlling the speaker. 
Sometimes this can make the game completely silent. And in the worst
case, it will reduce continuous, loud sound into intermittent, weak
sounds.

A potential problem with this solution is that the game might also 
provide its own clock interrupt handler, and if it decides not to
keep the original ISR active (i.e., maintain an interrupt handler chain),
all you have done might be in vain.

If you want to know more about the details, let me know.


Shuang
Newsgroups: comp.lang.c,comp.lang.c++
From: blume@kastle.Princeton.EDU (Matthias Blume)
Subject: C/C++ Correctness (was: Re: C/C++ Speed)
Reply-To: blume@kastle.Princeton.EDU (Matthias Blume)
Organization: Dept. of Computer Science, Princeton University
Date: Mon, 11 Jan 1993 22:42:38 GMT

The question should be: are programs written in C++ more reliable than those
written in C.  I serioulsy doubt that!

	C++
		- is highly complicated
		- has no fixed specification (or rather: the specification is
		  a moving target)
		- employs a syntax that is even more ambiguous than that of C
		- has NO WORKING compiler that really implements the language
		  (all compilers show major shortcomings in basic areas like
		  constructor/destructor call placement)
		- is overfeatures (who needs multiple inheritance?)

I'd rather stick to something simpler and more reliable than that.  If you
need inheritance et al. then use something that isn't suffering feature
cancer (for instance: Objective C)!  With a bit of discipline it is even
possible to write OO-programs in plain old C (Many people have done this as
an exercise, and literature about it will probably (hopefully) appear soon.)
The sad truth is, however, that almost everybody seems to believe in C++
nowadays... :(  C++ will not be the solution to the current software crisis --
it will be the cause of the next one.

-Matthias
Newsgroups: comp.lang.c
From: eager@eagercon.com (Michael J. Eager)
Subject: Re: can a pointer cast to a void* be compared to (void*)0 ?
Reply-To: eager@eagercon.com
Organization: Eager Consulting
Date: Mon, 11 Jan 1993 06:14:16 GMT

In article CqM@cs.psu.edu, andrew@astro.psu.edu (Andrew Wilcox) writes:
>This may be a FAQ, but I didn't see it in Steve Summit's excellent
>list, so:
>
>Can a pointer which has been cast to a void* be directly compared with
>a (void*)0 in ANSI C, or does the void* have to be cast back to the
>original type before the comparision?  I.e.,
>
>     char* c = 0;
>     void* p = (void*) c;
>     if (p == 0)
>       printf( "yes\n" );
>
>Is this program guaranteed to print "yes"?

Yes.  Zero is a "special" pointer value which is guaranteed to be different
from any valid pointer value.  A zero typed pointer value will be
converted (trivially) to a zero void pointer value.

---
Michael J. Eager		Michael.Eager@eagercon.com
Eager Consulting		(415) 325-8077 
1960 Park Boulevard, Palo Alto, CA 94306-1141

Newsgroups: comp.lang.c
From: tye@spillman.uucp (E. Tye McQueen)
Subject: Re: Debugging with 2 terminals. HELP!!!!!
Date: Sun, 10 Jan 1993 06:04:51 GMT
Distribution: usa
Organization: Spillman Data Systems

herring@netcom.com (John Herring) writes:
)Does anyone know of a debugger that will allow me to run the program on
)one terminal and debug using the debugger in another terminal?

Well, you say "terminal" so I'll assume you aren't talking about
MS-DOG.  So I'll just assume you want to do this on Unix (because
otherwise I don't have an answer for you).

Take your favorite debugger (ie. probably the only one available),
say sdb, and start it up on the terminal you want to debug from.
Then tell the debugger to start the program with input and output
(ie. stdin, stdout, and stderr) directed to the device (port)
connected to the terminal that you want the program to "run" on.

Actually, the debugger probably won't let you redirect stderr
but luckilly the debugger probably doesn't use stderr so you can
do something like:

    $ sdb program 2>/dev/ttya9
    *r arg1 </dev/ttya9 >/dev/ttya9

This is assuming that you aren't using the C shell.  If you are
using the C shell, you can do it too but it is a bit of a pain
(I'll let you figure it out).

If you have dbx, use "run" instead of "r".

Don't bother using CodView unless you debug from the console.

gdb passes the arguments to your shell so you can redirect
stderr with it.

 tye@spillman.com                         Tye McQueen, E.
----------------------------------------------------------
 Nothing is obvious unless you are overlooking something. 
----------------------------------------------------------
From: jfw@ksr.com (John F. Woods)
Newsgroups: comp.lang.c
Subject: Re: NH-- > NH
Date: 8 Jan 93 18:16:22 EST

keith@torme.sharebase.com (Keith Chambless) writes:
>In article <C0JMw6.680@netnews.jhuapl.edu> bandy@netnews.jhuapl.edu (Mike Bandy) writes:
>>So what you're saying is that NH > NH.  I don't believe it.  Your 
>>compiler (or your logic) has some serious problems.

No, the code has an obvious bug.  In ANSI Standard C (the only C in which you
can really talk about guarantees of behavior), it is explicitly undefined
behavior to modify an object in a statement (more precisely, between two
"sequence points") and evaluate it separately; to use a concrete example,

	if (nh-- > nh)

can perfectly well be compiled as

	MOV	nh,r0
	SUB	$1,nh
	MOV	nh,r1
	CMP	r0,r1

or

	MOV	nh,r0
	MOV	nh,r1
	SUB	$1,nh
	CMP	r0,r1

i.e. the second evaluation of nh is permitted to be either before or after
the side effect takes place; in fact, as far as ANSI C is concerned, the
side effect *need not* take place, and there need be *no* evaluation of
nh -- "undefined behavior" means completely undefined and unrestrained:
if you violate the warranty, _anything_ is allowed to happen.  The compiled
program could print "BOZO!" to the standard error stream, the CPU could melt,
a hand could reach out of the monitor and slap the programmer silly (would
that it could).

As far as pre-ANSI C goes, there was no formal description of the semantics
of the language (and K&R I glossed over the timing of side effects because
depending on the timing is tasteless :-), so it's kind of pointless to argue
about whether the above behavior is "right" for pre-ANSI C.
Newsgroups: comp.lang.c
From: bandy@netnews.jhuapl.edu (Mike Bandy)
Subject: Re: How to read without echo.
Organization: JHU/Applied Physics Laboratory
Date: Mon, 4 Jan 1993 17:54:39 GMT

vyskocil@taloa.unice.fr (Vyskocyl) writes:

>I only want to read a word on the keyboard without any
>print on the screen. I mean, I want someone to answer
>a question on his keyboard without any echo of what he
>is typing. It will end just after he pressed 'return'.

You'll have to find the operating system specific call to turn
off echo for the keyboard.  C does not have a built in routine
to do that, but your operating system (you don't say what
environment you're running under) probably does.

-- 

	Mike Bandy
	bandy@aplcomm.jhuapl.edu
	Johns Hopkins University / Applied Physics Lab
From: volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe)
Newsgroups: comp.lang.c
Subject: Re: NH-- > NH
Date: 11 Jan 93 17:04:48 GMT
Reply-To: volpe@ausable.crd.ge.com
Organization: GE Corporate Research & Development

In article <1iqal5INNbef@chnews.intel.com>, bhoughto@sedona.intel.com (Blair P. Houghton) writes:
|> The order of evaluation of operands in a binary expression
|> is implementation defined.
      ^^^^^^^^^^^^^^^^^^^^^^^

It's unspecified, not implementation defined.

-- 
==================
Chris Volpe
G.E. Corporate R&D
volpecr@crd.ge.com
Newsgroups: comp.lang.c
From: kheuer@gwdu03.gwdg.de (Konrad Heuer)
Subject: Tool for Automatic BASIC -> C Translation?
Organization: GWDG, Goettingen
Date: Fri, 8 Jan 1993 10:11:57 GMT


Imagine the following problem, please:

An old-fashioned BASIC program of about 3,500 lines has to be converted
to C. Maintenance of the resulting C code should be possible.

I'd greatly appreciate if anybody knows about a tool helping
to do that more or less automatically.

Thanks, K. Heuer.
Newsgroups: comp.lang.c,rec.humor