HDTenEightyP/NetNews huggingface dataset:
From: lastort@access.digex.com (Mike Lastort)
Subject: Re: HELP with C syntax checking programm
Keywords: c help braces { } fix syntax 
Organization: Express Access Online Communications, Greenbelt, Maryland USA
Distribution: all
Date: Fri, 11 Dec 1992 18:31:53 GMT

jhurwitz@access.digex.com (j. hurwitz) writes:

>Okay, I'm new to C so you'll have to forgive my lame question. Anyhoot,
>I'm trying to write a program that will check for balanced braces in my
>C source code. I hve no problem when I do this:

>=========================== Begin Hack =============================
>//programm to read a C source file and verify # of left to right braces
>#include <stdio.h>

>int main(int argc, char *argv[])
>{
>   FILE *fptr;
>   int l=0, r=0;
>   char ch;

>   fptr  = fopen("brachek2.c","r");

>   while ((ch =getc(fptr)) !=EOF)      //gets chars
>   {
>   if(ch=='{') l++;
>   if(ch=='}') r++;
>   }
>   if (l != r)
>  printf("\nBraces do not match\n");
>   else printf("\nBraces match !!!\n");
>   fclose(fptr);
>   return(0);
>}
>=========================== End Hack ===============================

>But, when I try this:

>============================== Begin Hack ==========================

>//programm to read a C source file and verify # of left to right braces
>#include <stdio.h>

>int main(int argc, char *argv[])
>{
>   FILE *fptr;
>   int l=0, r=0;
>   char ch;

>   fptr  = fopen("brachek3.c","r");

>   while ((ch =getc(fptr)) !=EOF)      //gets chars
>   {
>   switch (ch)
>     {
>     case '{':  l++; 
>     case '}':  r++; 
>     }
>   }
>   printf("\nl= %d r= %d", l, r);
>   if (l != r)
>   printf("\nBraces do not match\n");
>   else printf("\nBrace match !!!\n");
>   fclose(fptr);
>}
>================================ End Hack ==========================
>I get an uneven number of braces at the end. I can't figure out what
>I am doing wrong. I'm sure it is a minor oversight on my part. Any help
>would be greatly appreciated. 


Ok, the problem is that when using a switch case, you need to break out,
or else you "fall through" to the next case. In other words, your code:
 
 
	switch (ch)
	  {
 	  case '{': l++;
	  case '}': r++;
	  }

will increment BOTH l and r if ch == '{', and increments r if ch == '}'.
You should do something like:


	switch (ch)
	  {
	  case '{': l++; break;
	  case '}': r++;
	  }

That way, if ch == '{', l gets incremented, then the next character is
examined. 

Mike
From: pjh@cs.tut.fi (Haavisto Petri)
Newsgroups: comp.lang.c
Subject: Re: Finding the number of days between two dates
Date: 16 Dec 1992 06:11:56 GMT
Organization: Tampere University of Technology
Distribution: world
NNTP-Posting-Host: vuoripyy.cs.tut.fi

In article <1fsk16INNhn0@cs.tut.fi> pjh@cs.tut.fi (Haavisto Petri) writes:
>
>I need to write a standard conforming implementation of a function
>that computes the number of days between two given dates. For example,
>given Dec. 6, 1992 and Dec. 24, 1992, the function should return 18.

I have now received several responses both by email and in the net.
After a lot of pain and agony I managed to get the thing working.

It is clearly best to convert the dates to Julian day numbers and then
subtract. The functions time(), mktime(), and difftime() are not
guaranteed to (and will not) cover wide ranges of dates.

The pain and agony resulted from a compiler bug (Microsoft C v6.00)
which made the Julian day inverse function given in "Numerical Recipes
in C" to subtly fail (those interested are referred to comp.std.c).

Thank you very much to everyone who replied.

Petri Haavisto                         pjh@cs.tut.fi
Signal Processing Laboratory           tel: +358 31 161 849
Tampere University of Technology       fax: +358 31 161 857
P.O.B. 553
SF-33101, Tampere
FINLAND
From: volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe)
Newsgroups: comp.lang.c
Subject: Re: HELP with C syntax checking programm
Keywords: c help braces { } fix syntax
Date: 13 Dec 92 01:20:16 GMT
Reply-To: volpe@ausable.crd.ge.com
Distribution: all
Organization: GE Corporate Research & Development

In article <Bz3pCy.380@access.digex.com>, jhurwitz@access.digex.com (j. hurwitz) writes:
|> Okay, I'm new to C so you'll have to forgive my lame question. Anyhoot,
|> I'm trying to write a program that will check for balanced braces in my
|> C source code. I hve no problem when I do this:
|> 
|> =========================== Begin Hack =============================
|> //programm to read a C source file and verify # of left to right braces
|> #include <stdio.h>
|> 
|> int main(int argc, char *argv[])
|> {
|>    FILE *fptr;
|>    int l=0, r=0;
|>    char ch;

Here is a problem, though it's not what's causing your problems. "Ch" must
be declared an int, not a char, because that is what getc returns. The reason
is that a char cannot hold all the characters AND a unique EOF value. So,
depending on how your system implements chars (are they signed or unsigned?),
either a valid character will be mistaken for EOF, or EOF will be mistaken
for a valid char. 

|> 
|>    fptr  = fopen("brachek2.c","r");
|> 
|>    while ((ch =getc(fptr)) !=EOF)      //gets chars
|>    {
|>    if(ch=='{') l++;
|>    if(ch=='}') r++;
|>    }
|>    if (l != r)
|>   printf("\nBraces do not match\n");
|>    else printf("\nBraces match !!!\n");
|>    fclose(fptr);
|>    return(0);
|> }
|> =========================== End Hack ===============================
|> 
|> But, when I try this:
|> 
|> ============================== Begin Hack ==========================
|> 
|> //programm to read a C source file and verify # of left to right braces
|> #include <stdio.h>
|> 
|> int main(int argc, char *argv[])
|> {
|>    FILE *fptr;
|>    int l=0, r=0;
|>    char ch;
|> 
|>    fptr  = fopen("brachek3.c","r");
|> 
|>    while ((ch =getc(fptr)) !=EOF)      //gets chars
|>    {
|>    switch (ch)
|>      {
|>      case '{':  l++; 

Here's your real problem. You need a "break" separating the cases, otherwise
execution will flow from one case right into the next.

|>      case '}':  r++; 
|>      }
|>    }
|>    printf("\nl= %d r= %d", l, r);
|>    if (l != r)
|>    printf("\nBraces do not match\n");
|>    else printf("\nBrace match !!!\n");
|>    fclose(fptr);
|> }
|> ================================ End Hack ==========================
|> I get an uneven number of braces at the end. I can't figure out what
|> I am doing wrong. I'm sure it is a minor oversight on my part. Any help
|> would be greatly appreciated. 

-- 
==================
Chris Volpe
G.E. Corporate R&D
volpecr@crd.ge.com
Newsgroups: comp.lang.c
From: pirzyk@vinny.cecer.army.mil (Jim Pirzyk)
Subject: Re: Need HELP with strptime....any answers/clues?????
Organization: US Army Corps of Engineers Construction Engineering Research Labs
Date: Fri, 18 Dec 1992 19:47:52 GMT

In <BzDJuA.AGF@sdf.lonestar.org> jjunker@sdf.lonestar.org (Jon Junker) writes:

>Hi:
> 
>I have been working with some of the time functions (on a Sun
>SPARCstation IPX).  After I make a call to strptime (to fill 
>in the tm structure) I display the structure (with dbxtool) and
>find that the structure is filled in incorrectly.  What am I 
>doing wrong?
> 
>Please, e-mail me with the answer. Below is some example code.
> 
>Thanks for your time,
>Jon
>jjunker@sdf.lonestar.org
> 
> 
>        ---------- Example Call to AsciiToTime ----------
>				:
>				:
>				:
>	timeStatus = AsciiToTime("1990,123/065301.123");
>				:
>				:
>				:
> 
>        ---------- Module and Call in Question ----------

>#include	<time.h>
> 
>AsciiToTime(timeString)
>char	*timeString;
>{
>	struct	tm	*my_tm;
> 
>	/* Convert time string into the time structure (my_tm) */
>	(void)strptime(timeString,"%Y,%j/%H%M%S",my_tm);

strptime does not understand that the hour, minute, and second are only
certain lengths.  You need to have some other token to split the fields
like a colon, or space.

> 
>/* ---> After the above call to strptime the tm structure is not filled
>	in correctly. What am I doing wrong ??????
>*/
> 
>	return(0);
>}
-- 
[Jim] pirzyk@uiuc.edu ------------------------------------------
TAC System Administrator, US Army Corps of Engineers 
Construction Engineering Research Labs, Champaign IL USA
/* Contract employee, and do you think some federal paper pusher */
Newsgroups: comp.lang.c
From: saud@seas.gwu.edu (Temporary account (slc 11/19/92))
Subject: pointer assignment problem
Organization: George Washington University
Distribution: usa
Date: Sun, 13 Dec 1992 18:11:18 GMT

Hi:

I am having problem with pointer assignment 

look at this pleae
	
	function_node	*tmp_node;

	tmp_node = (function_node *) malloc (sizeof(tmp_node));
^^^^^^^
If I examine the content of tmp_node (p *tmp_node) in the debugger
I got 
	func_name = null ; pointer to char
	def_or_dec = null ; pointer to char
	line_number = 0 ; Int
	basic_type = ""; /* I do not know why even though its a point to char
	class_enclose = 0; /* pointer to an other structure
	next =0;    /* pointer to function_node structure (this struc)

^^^^^^^^^
	tmp_node->func_name = save_name (func_name);
save_name (code is eclosed) simple it will allocate space the copy this string
^^^^^^^^^
Now is the fun part
	once the above line gets executed the pointer class_enclose and next
get some garbage (values that does not make sense). any way wait

/* link to the CCB struct that encloses this function */
	if ( class_count ) {
		tmp_node->class_enclose = class_ptr;
OR with castign as
/*		tmp_node->class_enclose = (class_node *)class_ptr;  */
	}
^^^^^^^^^^^
here is the major problem
once the above line gets execute:...... The value of the pointer func_name gets
garbage suech as
	"@\002\213\X"
for example if you print the *tmp_node before executing the pointer assignment
	I got 
	tmp_node->func_name = "Basic_const";
after the pointer assignment I got 
    tmp_node->fun_name ="@\002\213\X_const"; part of the name was overwritten

could some one help please

thanks
wanes

here is th complete code if that help

THE SYSTEM THIS IS RUN ON IS HP-BOX 835E I guess
---------------------------
add_func(s)
char * s;
{
	
	function_node	*tmp_node;

	tmp_node = (function_node *) malloc (sizeof(tmp_node));

	tmp_node->func_name = save_name (func_name);
	if ( basic_type_name != NULL) {
		tmp_node->basic_type = basic_type_name;
	 	basic_type_name = NULL;
	}
	tmp_node->is_it_friend = is_it_friend;
	if (current_access_mode != NULL){
		tmp_node->access_type = save_name(current_access_mode);
	}
/* link to the CCB struct that encloses this function */
	if ( class_count ) {
/*		tmp_node->class_enclose = malloc(sizeof(class_node));  */
		tmp_node->class_enclose = (class_node *)class_ptr;
	}
	tmp_node->line_number = yylineno;
	tmp_node->def_or_dec	= save_name(s);
/*
	Link this functin to the list of the functions
*/

	if ( func_head == NillFunc) {
		func_head = tmp_node;
		func_tail = tmp_node;
		func_head->next = NillFunc;
	}
	else {
		func_tail->next = tmp_node;
		func_tail = tmp_node ;
	}
 }		


char *save_name(item_in)char *item_in;
{
	register char *dp;
	int     len ;

	len = strlen(item_in);
	dp = (char *)malloc(len+1);
	strncpy(dp,item_in,len);
	dp[len] ='\0';
	return dp;
}
Newsgroups: comp.lang.c
From: ghiya@cs.mcgill.ca (Rakesh GHIYA)
Subject: Programs that use function pointers!
Organization: SOCS - Mcgill University, Montreal, Canada
Distribution: w
Date: Sun, 13 Dec 1992 00:05:33 GMT

Hi,

I'm looking for C programs that use function pointers.
This is my second posting on the net : the first one
had a feeble response, unfortunately.

I'm doing an empirical study of C programs, to develop
a better understanding of the typical patterns in which
various C constructs are used in real life programs, and
help design of better static analysis tools for C.

Please mail preferably single file programs.

Hoping for a warm response,

Thanks in advance,

Rakesh Ghiya
School of Computer Science
McGill University
Montreal, Canada.
Newsgroups: comp.lang.c
From: swood@vela.acs.oakland.edu (Scott Wood - EVENSONG)
Subject: runtime needed (getting system time?)
Organization: Oakland University, Rochester MI.
Date: Tue, 15 Dec 1992 02:27:55 GMT

I have an assignment in which I need to monitor the runtime of the programs
that I am writing in order to compare them.  If someone can tell me the
best way to do this in C, it would be much appreciated.  Thanks....

swood

-- 
  Dec. 11   Opening day of Michigan Muzzleloading deer (zones 2 & 3)
  Dec. 13   Closing day of Michigan Muzzleloading deer (zone 1)
  Dec. 15   Closing day of late Michigan Elk season (permit only)
 All Month  Squirrel and Rabbit season(s) are still alive and well!!!
From: kdq@quest.UUCP (Kevin D. Quitt)
Newsgroups: comp.lang.c
Subject: Re: Questions about token merging and trigraphs
Date: Wed, 16 Dec 92 19:36:29 PST
Reply-To: srhqla!quest!kdq
Organization: Job quest  (805) 251-8210,  So Cal: (800) 400-8210

tanner@cdis-1.compu.com (Dr. T. Andrews) writes:

> ) What are trigraphs?
> Trigraphs are an unpleasant invention from the successor  to  the
> horse  committee...

    Perhaps Dr. Andrews should spend a little time in thought before
lashing out at necessary and occasionally useful, if obscure, parts of C.


> Trigraphs are a nasty way to write certain characters  in  the  C
> source  character  set.   These  more  difficult  characters  are
> represented  as  three  characters  starting  with   "??".    For
> instance, you can represent `#' as "??=".

    Trigraphs are the *only* way to represent certain critical
characters on machines that do not support the ASCII character set.
Their use on other machines is supported for portability.


> The change means that certain old programs may have strings, most
> likely error messages, compiled into something unexpected.

    I suppose anything is possible, but it's pretty remote.  Just how
remote it is, is easily shown by the fact that many experienced C
programmers know nothing about trigraphs; therefore they've never had a
problem from them.  The cost of something unexpected in an error string
is a fairly small price to pay for allowing non-ASCII machines to
support portable C code; after all, *code* isn't going to break.


 _
Kevin D. Quitt      96.37% of all statistics are made up.     srhqla!quest!kdq
Newsgroups: comp.lang.c
From: baileyc@ucsu.Colorado.EDU (Christopher R. Bailey)
Subject: SIGIO signal on HP pa-risc??? help needed
Keywords: SIGIO, fcntl, HP, System V, BSD, signal, socket
Organization: University of Colorado, Boulder
Distribution: usa
Date: Sat, 12 Dec 1992 00:59:23 GMT


I have some code I am trying to port to an HP pa-risc architecture machine.
The only thing it's choking on is some signal stuff.  It doesn't know about
the requests F_SETOWN and FASYNC.  This code works on Sun and Dec (and I think 
IBM RS/6000 :-).  I couldn't find anything in the man pages for fcntl() about
these.  They are used to allow the SIGIO and SIGURG signals.  I was wondering
how to implement this on an HP pa-risc machine.  I believe these are BSD
things, because the HP's we have that are running 4.3 BSD (HP 300's and 700)
have it.  This is being used in the app to receive X windows events and call
the signal handler which deals with the events.  If anyone has any example
code that would be great.  I guess this may be true for any Sys V???

Here is the two short functions that utilize SIGIO.

setup_sigio()
{
	sock = display->fd;
	socket_flags = fcntl(sock, F_GETFL, 0);
	socket_count = 0;
	signal(SIGIO, handle_sigio);
	fcntl(sock, F_SETOWN, getpid() );
}

enable_sigio()
{
	if(++socket_count == 1)
		fcntl(sock, F_SETFL, socket_flags | FASYNC);
}

disable_sigio()
{
	if(--socket_count == 0)
		fcntl(sock, F_SETFL, socket_flags & ~FASYNC);
}
-- 
Christopher R. Bailey            |Internet: baileyc@dendrite.cs.colorado.edu
University of Colorado at Boulder|CompuServe: 70403,1522
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Ride Fast, Take Chances!
Newsgroups: comp.lang.c
From: alan@sal.wisc.edu (Alan Watson)
Subject: Re: Questions about token merging and trigraphs
Organization: Space Astronomy Lab, Madison WI
Date: Thu, 17 Dec 1992 18:30:45 GMT

In article <mcdonald.610@aries.scs.uiuc.edu> mcdonald@aries.scs.uiuc.edu (J. D. McDonald) writes:
>That last it **UTTERLY WRONG**. I found that **many** of my programs
>broke!! **MANY** .. and they had lots of occurences of ??!, 
>??) ??(, ??[. and ??] in them, in **critical** places!!!
>
>I chose them as delimiters in a special ASCII file format for data,
>and chose them as no one would be likely to try to use them as
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>actual strings in the text-comment portion of the file!! They are coded
>into the program in strings .. and it would not have been so bad had
>not the idiotic ANSI committee decided that they would be replaced in
>strings as well as code!!

It sounds like your code was broken in the first place; never make 
assumption about what your users might and might not do.
Newsgroups: comp.lang.c
From: behrenss@Informatik.TU-Muenchen.DE (Soenke Behrens)
Subject: Re: Peek/Poke in C
Organization: Technische Universitaet Muenchen, Germany
Date: Sun, 20 Dec 1992 15:29:06 GMT

ray@philmtl.philips.ca (Ray Dunn) writes:

>In refd article, behrenss@Informatik.TU-Muenchen.DE (Soenke Behrens) writes:
>>>ericwebb@blackwlf.gwinnett.com (eric webb) writes:
[Peek and Poke]
>>Very implentation-specific. Some architectures allow something along
>>the lines of
>>char *address;
>>address = 0x678090;
>>*address = 80; /* poke $678090,80 */
>>printf ("And peek gives us: %d\n",*address);
>_All_ architectures allow the above constructions.  What is architecture
>specific is the range of numeric addresses which are meaningful, and
>whether the addresses are absolute or relative to some base or segment
>start address.  This is actually no different from PEEK and POKE in the
>general case.

Ok, so what I wanted to say is: In some architectures you get meaningful
results with this. The layout of a pointer depends heavily on which architecture you are on, theoretically it can consist of anything, with numerous fiuelds to show if the address is in physical or virtual memory, etc.,

Oh fuck, my monitor went blank. How i hate that. Grmbl.

Soenke
-- 
===========================================================================
More than silver, more than gold, I need   !    behrenss@informatik.
electricity. I need it for my dreams.      !    tu-muenchen.de
(RACTER)                                   !  FIDO: 2:246/13 Soenke Behrens
Newsgroups: comp.lang.c
From: ctaylor@cs.uiuc.edu (Conrad Taylor)
Subject: What should be returned by the functions...???
Organization: University of Illinois at Urbana-Champaign
Date: Sun, 20 Dec 1992 19:23:09 GMT


    What should the functions , insertright and insertleft, return because
I'm receiving errors with Borland C++ 3.1.  For exmaple, functions isn't
returning a value.  Thanks in advance to all that reply.

-Con

ps: My e-mail is ctaylor@silver.lcs.mit.edu or
    taylor1@wse.eecs.uic.edu. 


struct node {
   int info;
   struct node *left;
   struct node *right;
};

typedef struct node *NODEPTR;

NODEPTR insertright(NODEPTR p, int x); /* ins immediately to right of header */
NODEPTR insertleft(NODEPTR p, int x);  /* ins to the left of header          */
      
NODEPTR insertright(NODEPTR p, int x)
{
  NODEPTR q, r;

  if (p == NULL) {
     printf("void insertion\n");
     return;
     } /* end if */
  q = getnode();
  q->info = x;
  r = p->right;
  r->left = q;
  q->right = r;
  q->left = p;
  p->right = q;
  return;
} /* end insertright */

NODEPTR insertleft(NODEPTR p, int x)
{
  NODEPTR q, r;

  if (p == NULL) {
     printf("void insertion\n");
     return;
     } /* end if */
  q = getnode();
  q->info = x;
  r = p->left;
  r->right = q;
  q->left = r;
  q->right = p;
  p->left = q;
  return;
} /* end insertleft */


Newsgroups: comp.lang.c
From: tmc@spartan.ac.BrockU.CA (Tim Ciceran)
Subject: Spell Checking/Correction Algorithm
Organization: Brock University, St. Catharines Ontario
Date: Tue, 15 Dec 1992 05:17:58 GMT

I'm currently involved in a project in which an extensible spell
checking facility must be implemented to identify errors and suggest
alternative spellings. Does anyone happen to know of a good reference
or existing source code for such an algorithm? Any suggestions or
insights would be greatly appreciated.

Cheers,

TMC
From: ark@alice.att.com (Andrew Koenig)
Newsgroups: comp.lang.c
Subject: Re: Question to test general C knowledge
Date: 13 Dec 92 17:52:26 GMT
Article-I.D.: alice.24406
Reply-To: ark@alice.UUCP ()
Organization: AT&T Bell Laboratories, Murray Hill NJ

So far what I've seen under this banner have been interesting
exam questions for a course in programming technique.  I'd be
reluctant to use any of them to decide whether to hire someone,
partly because I think it's more interesting to try to find
out what a candidate has accomplished and partly because when
Bell Labs hired me in 1977, I had never written a line of C.
Of course, I told people that well in advance, along with the
fact that I knew a bunch of other languages and didn't think
I'd have any difficulty learning one more.

Anyway, enough reminiscinces.  My contribution to to the `exam
question for programming technique course' list is

	Part 1: Write a program to do a binary search.
	In case you've forgotten what that is, the parameters
	are an array and a single value of the same type.
	If it's a C program, the array is presumably
	expressed as a pointer to the initial element
	and a count.  The array is guaranteed to be sorted
	in increasing order.

	Your problem is to determine whether the value appears
	in the array and return either its index or a unique
	value indicating it isn't there.  You want to do this,
	of course, without looking at all the elements.  The
	binary search algorithm works by picking an element near
	the middle and seeing whether the value you're seeking
	is greater, less, or equal to that element.  If it's
	equal, you're done; if not, you've reduced the search
	space to half its previous value.  N successive bisections
	will search a table with O(2^n) values.


	Part 2: Does your program work?  How do you know?
	That is: either prove it works or write a second
	program to test it.


	Part 3: The algorithm depends critically on the table
	being already sorted.  Would it be a good idea to make
	the program more robust by checking that the table is
	indeed sorted before beginning the search?  Why or why not?

These questions expose quite a number of software engineering questions.
I find it remarkable how few people can answer them -- including people
who are making a living trying to solve much harder problems.
-- 
				--Andrew Koenig
				  ark@europa.att.com
Newsgroups: comp.lang.c
From: millertr@cuugnet.cuug.ab.ca (Trever Miller hm 276-2120 wk 263-2600)
Subject: Re: ISAM routines
Organization: Calgary UNIX Users' Group Association
X-Newsreader: TIN [version 1.1 PL8]
Date: Fri, 18 Dec 1992 13:21:22 GMT

Matthew Jackson (s9100786@cumulus.csd.unsw.oz.au) wrote:
: Does anyone know of any routines to implement ISAM under C ? We are 
: working on a project which needs indexed sequential access and (as 
: always) don't want to reinvent the proverbial wheel.

: I checked archie for isam and no luck.

Ask archie about "cbase"

: Thanks for any help,

--
#include <standard.disclaimer>                "Boot to the head! Nyah Nyah!"
                                                       - The Frantics
Internet : millertr@cuug.ab.ca (preferred)  
           trever%pixel@fsa.cpsc.ucalgary.ca    PGP2.1 PubKey avail on request
Newsgroups: comp.lang.c