kkrueger@zeus.unomaha.edu (Kurt Krueger) (03/30/91)
Originally, I posted this on com.os.vms, but I haven't had any responses yet,
and I thought the gurus on this newsgroup could be of help.
I have been working on a simple C program to supplement a DCL program. It is
passed two parameters: a filename and the length of the file in bytes. It
outputs the length of time the file will take to transfer at 2400bps. I would
have written the whole thing in DCL except that DCL can't do floating point
operations. I wrote and compiled my program on my Amiga, and it runs fine;
however, I can't get it to run on our VAX. I know next to nothing about C
programming on the VAX (the truth is, I know little about C, as well), and I
would be happy if someone could point out my folly. The program is as follows:
extern int atoi();
float size, time;
int block, mins, secs;
main (argc, argv)
int argc;
char *argv[];
{
int result, value();
printf ("%s", argv[1]);
block = value(argv[2]);
size = block / 2;
time = size / 0.2227;
mins = time / 60;
secs = time - (mins * 60);
printf ("\t\t%d\t%d\n", mins, secs);
}
int value(number1)
char *number1;
{
int convblock = atoi(number1);
}
(I realize that a one-line function is strange, but this is only part of
what the whole program will be.) I compiled the program on the VAX and then
linked it with the sharable vaxcrtl library as specified in the last Info-VAX.
Here is the correct output of the program as compiled on my Amiga:
RAM DISK:> test filename 55
filename 2 1
RAM DISK:> test filename 45
filename 1 38
"Test" is the name of the program, the first parameter is "filename" and the
second is "55", which refers to the block size. The program prints out that
the file will take 2 mins., 1 sec. to transfer (I haven't refined the xfer
times yet). Here is the output from the VAX:
$ test filename 55
filename 30124390 24
$ test filename 45
filename 30124390 24
Obviously, something is wrong (well, this is almost plausible at 300 baud). Is
it something to do with the floating point libraries? I am only a computer
user by hobby, so forgive me because I know this entire post is mighty elemen-
tary to a real programmer.
Also, how do I set the tabs on the VAX? I would like to have the first tab at
30 or 40.
Thanks in advance,
--
Sign below. Type hard, you are making thousands of copies.
-----------------------------------------------------------------------------
Kurt Krueger | BITNET: kkrueger@unoma1 | //\
MBA student | Internet: kkrueger@zeus.unomaha.edu | \X/--\ M I G A
-----------------------------------------------------------------------------kkrueger@zeus.unomaha.edu (Kurt Krueger) (03/30/91)
In article <1991Mar30.161854.27378@cbnewsk.att.com>, linwood@cbnewsk.att.com (linwood.d.johnson) writes: > Wouldn't you want this function to return something since you are > using the return value. > > I think something like: return( convblock); > > will do the trick. It will, indeed. My mail box has been flooded with responses to this question, and a lot of people were very kind in providing me with answers and a number of additional tips that will prove very valuable in the future. Thanks to the multitude. Kurt Krueger MBA student looking for work in a recession kkrueger@zeus.unomaha.edu
linwood@cbnewsk.att.com (linwood.d.johnson) (03/31/91)
In article <11697.27f376d8@zeus.unomaha.edu> kkrueger@zeus.unomaha.edu (Kurt Krueger) writes: >I wrote and compiled my program on my Amiga, and it runs fine; >however, I can't get it to run on our VAX. I know next to nothing about C >programming on the VAX (the truth is, I know little about C, as well), and I >would be happy if someone could point out my folly. The program is as follows: > >extern int atoi(); >float size, time; >int block, mins, secs; > >main (argc, argv) > >int argc; >char *argv[]; > >{ > int result, value(); > printf ("%s", argv[1]); > block = value(argv[2]); > size = block / 2; > time = size / 0.2227; > mins = time / 60; > secs = time - (mins * 60); > printf ("\t\t%d\t%d\n", mins, secs); >} > >int value(number1) >char *number1; >{ > int convblock = atoi(number1); ****** Wouldn't you want this function to return something since you are using the return value. I think something like: return( convblock); will do the trick. >} -- | Linwood D. Johnson | linwood@ihlpf.att.com | | AT&T Bell Labs, 1000 E. Warrenville Rd., Naperville, IL 60566 | | Disclaimer: Opinions expressed here are mine and mine only. | | Besides, who else would want them? |
browns@iccgcc.decnet.ab.com (Stan Brown) (04/02/91)
[attribution suppressed so as not to embarrass anyone] > I think something like: return( convblock); > will do the trick. I bet if you stopped 100 C programmers, more than 50 of 'em would tell you that parentheses are part of the return statement, just like if, while, do, and for. They're not. I don't want to start another religious war (the one on EQU or == is enough excitement for me), but since the ( ) don't add anything to a return statement I'd suggest leaving them out. My opinions are mine: I don't speak for any other person or company. email (until 91/4/30): browns@iccgcc.decnet.ab.com Stan Brown, Oak Road Systems, Cleveland, Ohio, USA +1 216 371 0043
henry@zoo.toronto.edu (Henry Spencer) (04/02/91)
In article <4072.27f7215c@iccgcc.decnet.ab.com> browns@iccgcc.decnet.ab.com (Stan Brown) writes: >I bet if you stopped 100 C programmers, more than 50 of 'em would tell >you that parentheses are part of the return statement, just like if, >while, do, and for. They're not. They used to be, actually, and many of the role models :-) for C programmers have habits dating back to the time when they were. -- "The stories one hears about putting up | Henry Spencer @ U of Toronto Zoology SunOS 4.1.1 are all true." -D. Harrison| henry@zoo.toronto.edu utzoo!henry
darcy@druid.uucp (D'Arcy J.M. Cain) (04/02/91)
In article <4072.27f7215c@iccgcc.decnet.ab.com> Stan Brown writes: >I bet if you stopped 100 C programmers, more than 50 of 'em would tell >you that parentheses are part of the return statement, just like if, >while, do, and for. They're not. You must be moving in the wrong circles. Ask around here and I bet hardly anyone thinks that parentheses are required in the return statement. However parentheses are always allowed around *ANY* expression so what's the big deal if someone wants to put them there? I bet you also have a problem with: if ((a == 1) || (a == 5)) ... >I don't want to start another religious war (the one on EQU or == is >enough excitement for me), but since the ( ) don't add anything to a >return statement I'd suggest leaving them out. And I suggest using as many as make you comfortable. I don't want to shock anyone but I have been known to do the following and I am totally unrepentant: return(5 + (a * k)); Whitespace doesn't add anything to the program either. Should we leave that out as well? -- D'Arcy J.M. Cain (darcy@druid) | D'Arcy Cain Consulting | There's no government Toronto, Ontario, Canada | like no government! +1 416 424 2871 |