HDTenEightyP/NetNews huggingface dataset:
From: kenneths@tropicana.ai.mit.edu (Kenneth J. Schneider)
Newsgroups: comp.lang.c
Subject: if and case alternative
Date: 19 Dec 1992 16:44:55 GMT
Organization: MIT Artificial Intelligence Lab
Distribution: world
NNTP-Posting-Host: tropicana.ai.mit.edu

on the previous if/case thread...

one not-so-readable way to avoid the slowness of a *large* list of if/else's or
cases would be to make an array of pointers to the functions. this would, i
believe, quite a bit slower for a small number of cases, but would be much better
(for speed) for a large number of cases. 

comments?
From: davisks@csugrad.cs.vt.edu (Kenneth S. Davis)
Newsgroups: comp.lang.c
Subject: Arbritary Precision Math
Date: 12 Dec 92 04:48:25 GMT
Organization: Virginia Tech Computer Science Dept, Blacksburg, VA

Does anybody have any C routines that handle arbritary math?  I have no
problem with addition, subtraction and multiplication.  I do have a problem
with division, though.  I would hate to dig up my old computer architecture
book and handle division in a binary format (like an ALU).  It would be nice
if I could do the division 8 bits at a time, at least.

--Ken
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.c
Subject: Re: Yet another time.h question (organisation of struct tm)
Keywords: organisation of struct tm
Date: 15 Dec 92 03:43:38 GMT
Organization: Comp Sci, RMIT, Melbourne, Australia

In article <1g8chcINNenv@almaak.usc.edu>, ajayshah@almaak.usc.edu (Ajay Shah) writes:
> I'm trying to replace the initialisor
> 
> #define TINIT(T)  (T).tm_sec = (T).tm_min = (T).tm_hour = 0; \
>     (T).tm_mday = 1; (T).tm_mon = 0; (T).tm_year = 0; \
>     (T).tm_wday = -1; (T).tm_yday = -1; (T).tm_isdst = -1

> But this will only work if ANSI guarantees that the fields in the
> tm struct-type come in the order I've assumed above.  Do they?

"The members ... can occur in any order."  (Plauger & Brodie)

> Is there any gain from using memcpy here, or is the painful
> element-by-element initialisation quite fine?

Wouldn't it be more efficient still to represent dates as time_t's,
and set up your default_time value using the result of mktime()?

> (A 100% C programmer who still likes the Pascal ability to say a:=b
> even when a and b are records :-)).

C has had that ability for many years.
From: kmcclare@ncrclm.ClemsonSC.NCR.COM (Ken McClaren)
Newsgroups: comp.lang.c
Subject: Access to Indexed Sequential files
Date: 15 Dec 92 20:53:26 GMT
Reply-To: kmcclare@ncrclm.ClemsonSC.NCR.COM (Ken McClaren)
Distribution: usa
Organization: NCR E&M CLEMSON Liberty, SC

I have yet another really basic question. Is there a way to access rm/cobol85
Indexed Sequential Files from c? I hate dragging the cobol runtime from system
to system when I want to pull data from a indexed file. 

        tks in advance,
                ken.
--
From: Mike.Tedder@f181.n363.z1.fidonet.org (Mike Tedder)
Newsgroups: comp.lang.c
Subject: 256 colors VGA 640x480
Date: Fri, 18 Dec 92 17:44:00 PDT
Organization: FidoNet node 1:363/181

* In a message originally to All, Michael J. Tihen said:
 > From: C600689@mizzou1.missouri.edu (Michael J. Tihen)
 > Date: Sat, 12 Dec 92 21:51:18 CST
 > Organization: University of Missouri
 > Message-ID: <168BB13356.C600689@mizzou1.missouri.edu>
 > Newsgroups: comp.lang.c

 > I am trying to use VGA graphics mode 640 x 480 with 256
 > colors using Turbo C,
 >  and I am looking for a method that does not require assembly
 > coding.  I have V
 > GA256.BGI and SVGA256.BGI, and was curious about their usage.
 >
 >   Thanks.

I've got the SVGA256.BGI on my system over here. (1:363/181 at (407)438-8548) Perhaphs this can help you.  It supports resolutions from 320x200x256 to 1024x768x256.  BUT, that isn't what you're looking for.

You want source code to things like this.... First off, I would recommend dumping the Borland Graphics Interface.  It's slow, and performs terribly.  I have created a library of my own, but it doesn't cover as much as the BGI interface does.  (Such as getimage(), putimage(), setaspectratio(), etc)  But, it also has advantages over the interface.  It's faster, and since it is dedicated to 256 colors, you can easily capture the palette (using getrgbpalette() at any time) or other advanced things.

At this time, I'm not thouroughly finished with it.  It works fine in 320x200x256, but I experience problems when I get into plane-shifting for the SuperVGA modes.  I also only have support for a Trident board (what I am now using).  If you have the specs for the hi-res modes (Mode number in hex, pixels horiz, pixels vert), leave me a message, and I'd appreciate it.

I'll keep you updated on it's progress.

--  
        Mike Tedder  -  via FidoNet Node: 1:363/42
             UUCP:  -  ...tarpit!tous!business!181!Mike.Tedder
             ARPA:  -  Mike.Tedder@f181.n363.z1.fidonet.org
Newsgroups: comp.lang.c
From: stasica@alumni.cs.colorado.edu (The Legacy)
Subject: Performance Monitor
Organization: Mile High
Date: Thu, 17 Dec 1992 22:14:29 GMT

Here's an interesting problem I have been given and want to know if anyone
can help me out on ideas.

The purpose of the program is to perform various tasks that utilize system
resources such as CPU, Memory, and Disk I/O.  Every 15 minutes it does these
three tasks, records the times for each and goes back to sleep.  The output
is used for tracking performance of each three over a period of time.

My question is, what kinds of algorithms in "C" would one use that would
sufficiently test a system's resources on a multi-user system, in which the
code is portable over multiple platforms.

My ideas are basically the following:
CPU test: run through a loop many times, doing some calculations
Memory:  malloc() a couple megs of memory and push some values into memory
Disk:     Create a sizeable file and read it back in

Is there any good code that does these kinds of tests already (where?)?
What might code look like that would make these tests feasible?

You can reply in mail or if you think it is worth discussion, reply here!
-- 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* "What do you mean I don't get to work on time... got nothing better to do." *
* "What do you mean I don't pay my bills... why do you think I'm so broke?"   *
*                       stasica@alumni.cs.Colorado.EDU                        *
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.c
Subject: Re: Getting input from the keyboard
Date: 18 Dec 92 06:16:25 GMT
Organization: Comp Sci, RMIT, Melbourne, Australia

In article <1992Dec14.212611.12032@cs.mun.ca>, paulk@garfield.cs.mun.ca (Paul E. King) writes:
> I am beginner in the C language, and was wondering if anyone is willing to
> help me on what seems to be an unsolvable problem(so far).

This is not a C language question.  It is an operating system question.

> I am told by one of the profs that what I seem to be asking is how to enter
> CBREAK mode. Apparently this seems to have something to do  with a 
> function called ioctl(), and "orring" one hex constant into another.

> I am using a UNIX-based System V Berekley C compiler.

This is passing strange, sort of like "I vote the Democratic Republican
ticket".

The _real_ place to start looking is the UNIX System V documentation set.
(If you have Berkeley UNIX, you have the "Supplementary documents" some-
where in your document set, and there is a brief intro to UNIX programming
in that.)

The very simplest way to control the terminal is to use the exact same
stty(1) command that you use from command level.  Use the command
	man stty
or perhaps
	man 1 stty
That will direct you to ioctl(2) and termio(7), but the simplest method
to get right is 

	/* The terminal driver is in its ordinary line-at-a-time mode */
	system("stty raw");
	/* Now the terminal driver is in character-at-a-time mode */
	use the 'read' system call to read from stdin
	system("stty cooked");
	/* Now the terminal driver is back in line-at-a-time mode */

This will cost you a lot more CPU cycles than calling ioctl(), but it
is much easier to get right.

A far better thing to do is to keep looking in your documentation set.
There is a package called "Curses".  The UNIX System V documentation set
contains an introduction to Curses.  Some bookshops used to carry the
generic System V Release 3 documents, fairly compact but fairly thick
paperbacks.  There is a Curses tutorial in that lot.

The documentation that comes with SunOS (which runs on the Sparc-stations)
can fairly be called "copious".  It includes an introduction to UNIX
programming and an introduction to Curses.

VMS also has a "curses" implementation, and there are a couple of free/cheap
ones for DOS.
Newsgroups: comp.lang.c
From: stanleyr@kramden.nyu.edu (Rick Stanley)
Subject: Re: Rounding floats to X significant digits
Keywords: rounding float significant digits
Organization: New York University
Distribution: usa
Date: Sat, 12 Dec 1992 16:01:16 GMT


ethan@earl.scd.ucar.edu (Ethan Alpert) writes:
 
>I apologize if this appears in a FAQ.

>I was wondering if anyone has any interesting techniques for rounding
>floating point numbers to a certain number of significant digits?

>I'm not talking a certain number of characters but a certain number
>of significant digits, decimal places.

>There doesn't appear to be a standard C library routine for this.

>Sprintf only does it for digits *left* of the decimal place and not
>for the entire number.

>Here's what I came up with and I'm still not sure it works.

>There has to be a better way to do it. 

>#include <stdio.h>
>#include <math.h>

>float roundit(float a, int sig_digit)
>{
>	char buf[20];
>	char format[20];
>	float exp;
>	float tmp1;
>	

>	sprintf(format,"%%.%df",sig_digit);
>	if(a > 1.0) {
>		exp = (float)log10((double)a);
>		exp = (float)ceil((double)exp);
>		tmp1 = (float)pow((double)10.0,(double)exp);
>		sprintf(buf,format,a/tmp1);
>		return((float)atof(buf)*tmp1);
>	} else {
>		sprintf(buf,format,a);
>		return((float)atof(buf));
>	}
>} 

How about the following, which works well for me.

/* -----------------------------------------------------------------------
FILE: Round.cpp          AUTHOR: Rick Stanley             CREATED: 10/10/91
DESCRIPTION: Round a double number to n decimal places.  for use in rounding
off dollar amounts to 2 decimal places for increased accuracy in calculations
and display.  I can't trust the accuracy of printf() using floats.
--------------------------------------------------------------------------
Copyright (C) 1991, Rick Stanley (212) 569-9304  All Rights Reserved
-------------------------------------------------------------------        */
#include <stdio.h>
#include <math.h>
 
double round(double value, int precision);
 
double round(double value, int precision)
{
    double result, power;
    long ltemp;
    power = pow(10.0, (double) precision);
    result = (value * power + .5);
    ltemp = (long) result;
    result = ((double) ltemp) / power;
 
    return result;
}

/* Where precision is the number of decimal places to round for,
   dollars = round(dollars, 2); to round to 2 decimal places.  */

I've seen this reduced to one line of code, but prefer to do it this way.
I believe this will work using negative precision thus rounding the
left side of the decimal point.  I have not used it that way.  Test it!

-------------------------------------+-----------------------------------
Rick Stanley                         | R.S. Consultants  (212) 569-9304
stanleyr@acf14.nyu.edu               | 
Information Technologies Institute   |        C++ & C Language
New York University   NYC, NY  USA   | Programming, Training, Consulting
-------------------------------------+-----------------------------------
From: ktf@bc3.GUN.de (Klaus ter Fehn)
Newsgroups: comp.lang.c
Subject: Re: Writing and reading from a device
Date: 19 Dec 92 12:34:30 GMT
Organization: private

In article <009653D6.94D9B200@vms.csd.mu.edu> 5652garsidej@vms.csd.mu.edu writes:

>Hi,
>   I am trying to write a simple communication program that will basically
>read and write to a port that a modem is connected to (not quite fortunate
>to have tcp/ip yet).  The problem is that when I echo the output, not all
>of it is released by the buffer.  I am using SCOV5.  Any suggestions?  Also,
>if anyone has some source code to get me started, that would be great.

I'm not quite sure ... hmm ... first (even if it's a stupid remark) have you
flushed the output buffers (fflush()) ? Second, take a closer look to the
ioctl-Settings (Baud rate, HANDSHAKING(!)) ?

Greetings...
-- 
Klaus ter Fehn		<ktf@bc3.GUN.de>
Neanderstr. 4		{mcshh,smurf,unido}!easix!bc3!ktf
4000 Duesseldorf 1
FRG / Germany		Tel.: +49-211-676331
Newsgroups: comp.lang.c
From: scs@adam.mit.edu (Steve Summit)
Subject: Re: Question to test general C knowledge
Organization: none, at the moment
Date: Mon, 14 Dec 1992 04:36:55 GMT

There's probably a more appropriate place to discuss this, but
what the heck.

> I had to do this for co-ops in my past.  What I did was ask them to 
> [write] a small C function on paper.  
> ...
> 2.  Input is a pointer to an array of 10 integers.  Sort the array.

Sorting problems are certainly far and away the most common quick
programmer assessment questions, and probably account for a
significant fraction of the number of unnecessary (i.e. all of
them) bubble sort implementations in the world today.  What I'd
like to know is, would the people posing such questions grade me
higher or lower for presenting an answer which relegated all work
to qsort()?  (Chapter two of The Elements of Programming Style
opens with a similar observation: "If our purpose is to teach how
to compute the minimum, we write [code deleted] which is direct
and to the point...  But if we are just trying to get the job
done, we use the Fortran built-in function AMIN1[.])

					Steve Summit
					scs@adam.mit.edu
Newsgroups: comp.lang.c
From: C600689@mizzou1.missouri.edu (Michael J. Tihen)
Subject: 256 colors VGA 640x480
Organization: University of Missouri
Date: Sat, 12 Dec 92 21:51:18 CST

I am trying to use VGA graphics mode 640 x 480 with 256 colors using Turbo C,
 and I am looking for a method that does not require assembly coding.  I have V
GA256.BGI and SVGA256.BGI, and was curious about their usage.
 
  Thanks.
 
If anybody knows of a place for source code for this type of stuff is, Please e
-mail me at c600689@mizzou1.missouri.edu.
From: david.brooks@cutting.hou.tx.us (David Brooks) 
Newsgroups: comp.lang.c
Subject: Re: MOD File Structure
Date: 12 Dec 92  2:19:00 GMT
Distribution: world
Organization: The Cutting Edge - Houston, TX - 713-466-1525
Reply-To: david.brooks@cutting.hou.tx.us (David Brooks) 

CP>    I am looking for the internal file structure of Amiga .MOD files.  I
CP> would like to creat a library so that people can incorperate them into
CP> their games.  Plus creat an Editor for the IBM that would allow you to
CP> write them in a staff.  Any sources or information would be appreciated.
CP> Thanks!

   Call the nearest Amiga BBS and look for a program called MED (Music
Editor) the documentation that comes with it will tell you more than you
would ever want to know about the structure of .mod files.

Failing that, send me E-mail, and I will send the MED documentation to
you.

CP> --
CP> cparis@comtch.spk.wa.us (Curtis Paris)
CP> IEAx for lack of a better name... (509) 624-0744

     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     *                                   *     While there is a    *
     *          David J Brooks           * lower class I am in it. *
     *                                   *     While there is a    *
     *   David.Brooks@cutting.hou.tx.us  *  criminal element I am  *
     *                                   *         of it.          *
     *          No Disclaimers           *  While there is a soul  *
     *                                   * in prison I am not free *
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

 * Q-Blue v0.7 [NR] *                                                                
----
+---------------------------------------------------------------------+
| The Cutting Edge BBS (cutting.hou.tx.us)    A PCBoard 14.5a system  |
| Houston, Texas, USA    +1 713 466 1525          running uuPCB       |
+---------------------------------------------------------------------+
Newsgroups: comp.lang.c
From: wkwong@kalman.eng.ohio-state.edu (Waihon Andrew Kwong)
Subject: C <--> Fortran translator
Organization: The Ohio State University Dept of Electrical Engineering
Date: Fri, 18 Dec 1992 05:42:19 GMT

Greetings,

Is it possible to translate codes from C to Fortran back and forth?
I have a fortran program and I would like it to be translated into C
code. Is it possible??

Does anybody know a program will do this??

Any comments and info are welcome.
Thanks in advance,
Andy
From: pal@regent.e-technik.tu-muenchen.dbp.de (Peter Loibl)
Subject: Re: Getting input from the keyboard
Organization: Technical University of Munich, Germany
Date: Wed, 16 Dec 1992 10:22:35 GMT

paulk@garfield.cs.mun.ca (Paul E. King) writes:

[stuff deleted]

>I want to know how C  can obtain input from the keyboard directly,
>without my having to type a carriage return. I know that the vi editor 
>works on this principle (that is what I am using now). 

[stuff deleted]

>I am using a UNIX-based System V Berekley C compiler.

[stuff deleted]

Hi!

getc(FILE *stream) reads one single character from a certain stream.
Streams are: open files, stdin and stderr (stdout is also one, but
this makes little sense here).

You should try getc(stdin).

More details are on the manual pages.

Peter Loibl
pal@regent.e-technik.tu-muenchen.de
From: jott@crash.cts.com (Joan Tine)
Newsgroups: comp.lang.c
Subject: Re: Peek/Poke in C
Summary: plugh
Date: 18 Dec 92 12:03:39 GMT
Followup-To: comp.lang.c
Organization: CTS Network Services (crash, ctsnet), El Cajon, CA

In article <BV5XVB5w165w@blackwlf.gwinnett.com> ericwebb@blackwlf.gwinnett.com (eric webb) writes:
>Hi again.. does anyone know how to do equivalent of BASIC's PEEK & POKE 
>statements in C?  My guess is that you need to use a far pointer to the 
>type of data (i.e., char, int, etc.), and then stuff the ptr with the seg 
>& offset.  How does one do this stuffing?  Does anyone know of any other 
>way to do it??  I need to go both ways, esp. POKE.

You're talking Intel, with the seg's right?  Two ways: 32-bit address
constants and a MK_FP() call.
Either a char far * p = 0xb8000000 ;   (if you were going to copy
something to the start of the CGA RAM, for instance, or use the 
MK_FP(seg,offset) function to return the same kind of far pointer 
constant and store it in p.
Newsgroups: comp.lang.c
From: davidr@cs.uow.edu.au (David Ian Raymond)
Subject: Re: Question to test general C knowledge
Organization: Dept of Computer Science, Wollongong University, Australia
Date: Wed, 16 Dec 1992 23:14:49 GMT

d_north@ondec.lonestar.org (David G. North, CCP) writes:

>In article <Bz0A46.Cvu@watserv1.uwaterloo.ca>,
>  dmeister@mansci1.UWaterloo.ca (Darren Meister) writes:
>> this but, if you could ask someone one question to test if they
>> generally understand C what would it be. Thanks for your responses.
>After all the recent hubbub under the topic 'what do you say?'
>How about:
>  What's the difference between '=' and '=='?
>:):):)
>Or better yet, what is the type and value of the following expression:
>  "this is a test"[4]



I give up. What is it?



>-- 
>David G. North, CCP
>d_north@ondec.lonestar.org {...!texsun!montagar!ondec!d_north}
>onDEC systems                                 "Everyone's crazy but you & me...
>P.O.Box 795848, Dallas TX  75379-5848          and come to think about it, I'm
>(214)985-1316 ... (214)902-3957                not so sure about you either!"
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: recursive variable arguments, can it be done?
Date: 17 Dec 92 21:57:27 GMT
Organization: McGill Research Centre for Intelligent Machines

In article <9212142052.AA00201@intuitiveedge.com>, monty@intuitiveedge.com (Montgomery Zukowski) writes:

> Let's say I have two functions f1(...) and f2(...) which take a
> variable argument lists.

> Is there any way to have f1 call f2 function like printf() by passing
> part of the variable argument list (the last part), or if not, then
> the whole thing?

No.  You need to find or create a version of f2 that takes a va_list
parameter instead of all the variable arguments.  (In some
circumstances, taking a va_list * might be preferable.)  See the FAQ
for more.

> I know that printf() has another function vprintf() which has that
> sort of functionality, but I wonder if there is a simpler way to
> specify a va_list so I don't have to have another function
> declaration like vprintf does for printf.

No, there isn't; that's why vprintf exists.

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu
From: dsbb@ns1.cc.lehigh.edu (D. SPENCER BEECHER)
Newsgroups: comp.lang.c
Subject: Re: Question to test general C knowledge
Date: 14 Dec 92 16:44:00 GMT
Organization: Lehigh University

How about:

What is the difference between:

varname%3

and

varname&0x02

and why might one be more advantageous to use?


In all sincerity, you may find it more expeditious to
have the applicant write a routine or two which perform
the same function as code written by the previous holder
of the position (or holder of a similar position in the
company).  Compare the codes.
-- 
                   _ _     _ _     _ _
  -Spence         [O.O]   )x.x(   )O.O(
                    O       O      -*-
Organization: North Dakota Higher Education Computer Network
Date: Tue, 15 Dec 1992 11:55:10 CST
From: <NIBMSCM@NDSUVM1.BITNET>
Newsgroups: comp.lang.c
Subject: C Reverse Engineering

  In search of a reverse-engineering tool for 'C' source code (written
for windows).  Would like output of structure charts, class hierarchies,
logic flow charts, etc.  Any hints on available software would be
appreciated.
 ___________
|           |   Regards,
|                  Steve Malme
|   Fargo ->*|      Great Plains Software
|____________|      (nibmscm@ndsuvm1.bitnet)
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: Testing competence of potential hires
Date: 11 Dec 92 19:40:41 GMT
Organization: McGill Research Centre for Intelligent Machines

In article <1g9pm5INNosg@almaak.usc.edu>, ajayshah@almaak.usc.edu (Ajay Shah) writes:

> I thought up two questions.  What holes can you poke in them?

>    Consider this code fragment:  [...defective uppercase routine...]

>    b) What errors will the (ANSI) compiler choke on?
>         - it's a void and he's returning cde

The compiler may or may not "choke" on it.  It is probably required to
issue at least one diagnostic, but it's within its rights to ignore the
return value, or return it anyway (which can be possible on machines
where small return values go in a register or something)....

As for (a), the other half of (b), and (c), others have done as well as
I could for them.

> There is a C program which contains the line

> #include "min.h"

>    You are told it allows you to use a "function" min(a, b) which
>    returns the smaller of a and b (both integers).

>    Write a test program which will tell you whether min is a true
>    function, or a #define.

Since we're not required to distinguish between "a #define" or "a
#define with a function available as well", we can write

#include <stdio.h>
#include "min.h"

int main(void)
{
#ifdef min
 printf("min is a #define\n");
#else
 printf("min isn't a #define\n");
#endif
 return(0);
}

> Answer 1: [...]
> Answer 2: [...]

> A1. If it's written as #define min(a,b) a<b?a:b then ++i will get
>     executed twice, giving 4.  Otherwise the min will be 3.

That's right.  But it could be a #define of another form, that doesn't
evaluate its first argument twice....

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu