[comp.lang.c] Strange C Program

pjh@mccc.UUCP (Peter J. Holsberg) (02/25/88)

The following program compiles with no problems.  When run by a user, it
generates "EMT trap - core dumped" message, but when run by ROOT, it
works like a charm!  Help!!

=========================
#include <stdio.h>
#define MOD 65536
#define MULT 25173
#define ADD 13849

/* This program, named  CREATE ,creates pseudo random numbers and sends *  
 * them to a file named RANDOM.                                         */

main()
{
   int n,seed,fseed, i=1;
   FILE *fopen(), *of;

     of = fopen("random", "w");
     printf("\nHow many random numbers would you like to create?\n");
     scanf("%d", &n);
     printf("\nWith what number would you like to start the ");
     printf("pseudo number generator?\n");
     scanf("%d",&seed);

     while(i++ <= n)
     {
       seed = seed * MULT + ADD % MOD;
       fseed = seed % 100000;
       printf("%11d",fseed);
       fprintf(of, "%11d",fseed);
     }

}     

-- 
Peter Holsberg                  UUCP: {rutgers!}princeton!mccc!pjh
Technology Division             CompuServe: 70240,334
Mercer College                  GEnie: PJHOLSBERG
Trenton, NJ 08690               Voice: 1-609-586-4800

gwyn@brl-smoke.ARPA (Doug Gwyn ) (02/25/88)

In article <238@mccc.UUCP> pjh@mccc.UUCP (Peter J. Holsberg) writes:
>generates "EMT trap - core dumped" message, but when run by ROOT, it
>works like a charm!  Help!!
>     of = fopen("random", "w");
>       fprintf(of, "%11d",fseed);

Really, posting to the net is an expensive (to others!) way to do
your debugging.  The only reason I'm responding is to make the point
that the total absence of any error checking in your code has made
it extremely non-robust.  My suspicion is that for some reason you're
not able to create the file "random" for writing (perhaps there is
already one present owned by "root" and not publicly writable?).
The use in fprintf() of the NULL `of' value that you should have
checked for right after the fopen() can have strange results.

You should learn how to use the debugger(s) on your system; in
particular a function call traceback would show whether or not
the problem occurred inside fprintf(), and it would also show
what arguments the function received.

pjh@mccc.UUCP (Peter J. Holsberg) (02/27/88)

Excuse me.  Since I did not find any reference to that error message in
my docs, I thought it appropriate to post the question.

As far as using the debuggers provided with my SysVr3.0, I would love to
do that, but have been discouraged because of the lack of any tutorial
information and description of what the debugger reports, and because it
looks like I will have to learn 32000 assembly language to get any use
out of the sdb debugger.  If you know of a place where I can learn
something useful about sdb, please let me know.

-- 
Peter Holsberg                  UUCP: {rutgers!}princeton!mccc!pjh
Technology Division             CompuServe: 70240,334
Mercer College                  GEnie: PJHOLSBERG
Trenton, NJ 08690               Voice: 1-609-586-4800