Need help with C program

  • Follow


I am doing a project on a old 6.2 VMS system and I need help writing a
C program that will convert a date formatted like this "5-MAR-2000
05:35:30.25" into the number of nanoseconds since the beginning of VMS
time - Nov. 17, 1858, which would be formatted like this:
44589513302500000.
I have looked in this user group and there some C programs buried in
the messages that do similar to what I want, but every time I copy one
and try to get it to work, I get errors and I don't know enough about C
to know how to fix them, and don't plan on learning C, as this is a
one-time project and I will never need it again. But having this
snippet of code will make the project go a lot faster.
Thanks to any adventurous programmers.
Rich

0
Reply RJDurkee (14) 11/16/2005 7:00:15 PM

In article <1132167615.398744.159880@f14g2000cwb.googlegroups.com>, "RJDurkee" <RJDurkee@yahoo.com> writes:
> I am doing a project on a old 6.2 VMS system and I need help writing a
> C program that will convert a date formatted like this "5-MAR-2000
> 05:35:30.25" into the number of nanoseconds since the beginning of VMS
> time - Nov. 17, 1858, which would be formatted like this:
> 44589513302500000.
> I have looked in this user group and there some C programs buried in
> the messages that do similar to what I want, but every time I copy one
> and try to get it to work, I get errors and I don't know enough about C
> to know how to fix them, and don't plan on learning C, as this is a
> one-time project and I will never need it again.

I would strongly suggest programming it in a language you do know.
0
Reply Kilgallen (2737) 11/16/2005 7:14:42 PM


C is the only compiler we have, and the only reason we have it is
because one of the applications installed on the system needs it. I
have done no programming on the system except DCL programming, which I
am very familiar with. If what I want to do can be done using only DCL,
let me know.
Rich

0
Reply RJDurkee (14) 11/16/2005 7:28:37 PM

"RJDurkee" <RJDurkee@yahoo.com> wrote in message 
news:1132167615.398744.159880@f14g2000cwb.googlegroups.com...
>I am doing a project on a old 6.2 VMS system and I need help writing a
> C program that will convert a date formatted like this "5-MAR-2000
> 05:35:30.25" into the number of nanoseconds since the beginning of VMS
> time - Nov. 17, 1858, which would be formatted like this:
> 44589513302500000.
> I have looked in this user group and there some C programs buried in
> the messages that do similar to what I want, but every time I copy one
> and try to get it to work, I get errors and I don't know enough about C
> to know how to fix them, and don't plan on learning C, as this is a
> one-time project and I will never need it again. But having this
> snippet of code will make the project go a lot faster.
> Thanks to any adventurous programmers.
> Rich
>
People who can help you probably need to know whether you have the VAX  C 
compiler or the DEC C one.
Jim 


0
Reply j.n (116) 11/16/2005 9:54:53 PM

RJDurkee wrote:
> 
> I am doing a project on a old 6.2 VMS system and I need help writing a
> C program that will convert a date formatted like this "5-MAR-2000
> 05:35:30.25" into the number of nanoseconds since the beginning of VMS
> time - Nov. 17, 1858, which would be formatted like this:
> 44589513302500000.

first step is to convert this to binary form:


#include <descrip>



char date_char[20];
unsigned int date_bin[2] ;
int status;

$DESCRIPTOR(date_char_desc,"dummy");

strcpy("5-MAR-2000 05:35:30.25",date_char);
date_char_desc.dsc$w_length = strlen(date_char);
date_char_desc.dsc$a_pointer = date_char;


status = SYS$BINTIM(&date_char_desc, &date_bin[0] );


With VAXC, you could have simply said
$DESCRIPTOR(date_char_desc,"5-MAR-2000 05:35:30.25");
But DECC is fussy about this and for some reason $BINTIM requires the
buffer to be writeable (even though it doesn't write to it, so you must
copy the string constant to non-constant buffer).

What this does is get you a 64 bit number stored in 2 32-bit integers.
0
Reply jfmezei.spamnot4 (5184) 11/16/2005 11:03:43 PM

RJDurkee wrote:
> C is the only compiler we have, and the only reason we have it is
> because one of the applications installed on the system needs it. I
> have done no programming on the system except DCL programming, which I
> am very familiar with. If what I want to do can be done using only DCL,
> let me know.
> Rich
> 

Slightly wrong.  You also have Macro-32.  Still, you'd need to be a 
decent Macro-32 programmer, or it's probably harder than C.

-- 
David Froble                       Tel: 724-529-0450
Dave Froble Enterprises, Inc.      Fax: 724-529-0596
DFE Ultralights, Inc.              E-Mail: davef@tsoft-inc.com
170 Grimplin Road
Vanderbilt, PA  15486
0
Reply davef3 (3419) 11/17/2005 2:42:40 AM

JF Mezei wrote:
> RJDurkee wrote:
> 
>>I am doing a project on a old 6.2 VMS system and I need help writing a
>>C program that will convert a date formatted like this "5-MAR-2000
>>05:35:30.25" into the number of nanoseconds since the beginning of VMS
>>time - Nov. 17, 1858, which would be formatted like this:
>>44589513302500000.
> 
> 
> first step is to convert this to binary form:
> 
> 
> #include <descrip>
> 
> 
> 
> char date_char[20];

Not that I enjoy reading C code, but why the extra longword?  I had 
assumed that you'd use 1 for a lower bound, until I see use of array 
element 0 below.

I really shouldn't be picky for a Q&D, huh?

> unsigned int date_bin[2] ;
> int status;
> 
> $DESCRIPTOR(date_char_desc,"dummy");
> 
> strcpy("5-MAR-2000 05:35:30.25",date_char);
> date_char_desc.dsc$w_length = strlen(date_char);
> date_char_desc.dsc$a_pointer = date_char;
> 
> 
> status = SYS$BINTIM(&date_char_desc, &date_bin[0] );
> 
> 
> With VAXC, you could have simply said
> $DESCRIPTOR(date_char_desc,"5-MAR-2000 05:35:30.25");
> But DECC is fussy about this and for some reason $BINTIM requires the
> buffer to be writeable (even though it doesn't write to it, so you must
> copy the string constant to non-constant buffer).
> 
> What this does is get you a 64 bit number stored in 2 32-bit integers.


-- 
David Froble                       Tel: 724-529-0450
Dave Froble Enterprises, Inc.      Fax: 724-529-0596
DFE Ultralights, Inc.              E-Mail: davef@tsoft-inc.com
170 Grimplin Road
Vanderbilt, PA  15486
0
Reply davef3 (3419) 11/17/2005 2:46:46 AM

Dave Froble wrote:
> > char date_char[20];
> 
> Not that I enjoy reading C code, but why the extra longword?  

Actually, it should really be char date_char[24]. A date-time is 23
characters long  (with an extra byte for the dreaded null character in C).

BTW, did you break your Z key in anger trying to type my name ??? ;-)
:-) :-)
0
Reply jfmezei.spamnot4 (5184) 11/17/2005 3:08:48 AM

JF Mezei schrieb:
[...]
>
> char date_char[20];
> unsigned int date_bin[2] ;
> int status;
>
> $DESCRIPTOR(date_char_desc,"dummy");
>
> strcpy("5-MAR-2000 05:35:30.25",date_char);
[..]

Only two small comments:

1. The size [20] of date_char is too small. Better have it 24 to carry
the entire date/time string.
2. The order of the arguments to strcpy should be changed if the date
string should be copied to variable date_char:

       strcpy (date_char, "5-MAR-2000 05:35:30.25");
       /* strcpy (dest, src) ! */

Your solution tries to overwrite the (write-protected) string constant
with the garbage of an uninitialized variable.

Kind regards,
-Uli

0
Reply uli_bellgardt (12) 11/17/2005 9:45:20 AM

In article <437BBACA.39ACAB0D@teksavvy.com>, JF Mezei <jfmezei.spamnot@teksavvy.com> writes:
[...]
> char date_char[20];
> unsigned int date_bin[2] ;
> int status;
> 
> $DESCRIPTOR(date_char_desc,"dummy");
> 
> strcpy("5-MAR-2000 05:35:30.25",date_char);

strcpy -- just say no.  Especially when you're having trouble counting
characters.

strncpy
memcpy
LIB$SCOPY_R_DX

All much nicer.

	John Briggs
0
Reply briggs3 (572) 11/17/2005 2:51:26 PM

On 16 Nov 2005 11:00:15 -0800, RJDurkee <RJDurkee@yahoo.com> wrote:

> I am doing a project on a old 6.2 VMS system and I need help writing a
> C program that will convert a date formatted like this "5-MAR-2000
> 05:35:30.25" into the number of nanoseconds since the beginning of VMS
> time - Nov. 17, 1858, which would be formatted like this:
> 44589513302500000.

So today is the 147th anniversary of VMS:-)
0
Reply tom284 (1837) 11/17/2005 6:08:47 PM

In article <ops0ecoxqrzgicya@hyrrokkin>,
	"Tom Linden" <tom@kednos.com> writes:
> On 16 Nov 2005 11:00:15 -0800, RJDurkee <RJDurkee@yahoo.com> wrote:
> 
>> I am doing a project on a old 6.2 VMS system and I need help writing a
>> C program that will convert a date formatted like this "5-MAR-2000
>> 05:35:30.25" into the number of nanoseconds since the beginning of VMS
>> time - Nov. 17, 1858, which would be formatted like this:
>> 44589513302500000.
> 
> So today is the 147th anniversary of VMS:-)

Well, that explains what Ben Franklin needed the lightening for.
It was powering the VAX he had in the basement of Independance
Hall.  Was the Declaration of Independance written with DECWrite?

bill

-- 
Bill Gunshannon          |  de-moc-ra-cy (di mok' ra see) n.  Three wolves
bill@cs.scranton.edu     |  and a sheep voting on what's for dinner.
University of Scranton   |
Scranton, Pennsylvania   |         #include <std.disclaimer.h>   
0
Reply bill125 (2406) 11/17/2005 6:45:08 PM

In article <ops0ecoxqrzgicya@hyrrokkin>, "Tom Linden" <tom@kednos.com> writes:
>On 16 Nov 2005 11:00:15 -0800, RJDurkee <RJDurkee@yahoo.com> wrote:
>> I am doing a project on a old 6.2 VMS system and I need help writing a
>> C program that will convert a date formatted like this "5-MAR-2000
>> 05:35:30.25" into the number of nanoseconds since the beginning of VMS
>> time - Nov. 17, 1858, which would be formatted like this:
>> 44589513302500000.
>
>So today is the 147th anniversary of VMS:-)

Does that mean only 3 more years ?

-- 
Peter "EPLAN" LANGSTOEGER
Network and OpenVMS system specialist
E-mail  peter@langstoeger.at
A-1030 VIENNA  AUSTRIA              I'm not a pessimist, I'm a realist
0
Reply peter 11/17/2005 6:56:41 PM

JF Mezei wrote:
> Dave Froble wrote:
> 
>>>char date_char[20];
>>
>>Not that I enjoy reading C code, but why the extra longword?  
> 
> 
> Actually, it should really be char date_char[24]. A date-time is 23
> characters long  (with an extra byte for the dreaded null character in C).
> 
> BTW, did you break your Z key in anger trying to type my name ??? ;-)
> :-) :-)

I'm never angry when I type your name.  Much easier to laugh than get angry.

As for the key, a particular Blue & Gold MaCaw (mis)named Grace takes 
too many liberties when I'm not supervising.  Keys on the keyboard. 
Office chair with top half chewed off.  Much more.

-- 
David Froble                       Tel: 724-529-0450
Dave Froble Enterprises, Inc.      Fax: 724-529-0596
DFE Ultralights, Inc.              E-Mail: davef@tsoft-inc.com
170 Grimplin Road
Vanderbilt, PA  15486
0
Reply davef3 (3419) 11/17/2005 8:12:00 PM

> 
> So today is the 147th anniversary of VMS:-)

   VMS isn't so self centered.  Today is the 147'th anniversary of the
   start of the Smithsonian calendar.

0
Reply koehler2 (8190) 11/17/2005 8:25:36 PM

I get the following error when compiling the program snippet listed
above:

strcpy("5-MAR-2000 05:35:30.25",date_char);
  .......^
%CC-E-CLOSEPAREN, Missing ")".

I am using Dec CC.
I would also like the program to be able to accept one parameter - the
date in "5-MAR-2000 05:35:30.25" format, and have it create a
symbol with the converted time in it that I could read in a DCL
program.
Thanks
Rich

0
Reply RJDurkee (14) 11/18/2005 2:50:01 PM

On 18 Nov 2005 06:50:01 -0800, RJDurkee <RJDurkee@yahoo.com> wrote:

> I get the following error when compiling the program snippet listed
> above:
>
> strcpy("5-MAR-2000 05:35:30.25",date_char);
>   .......^
> %CC-E-CLOSEPAREN, Missing ")".
>
> I am using Dec CC.
> I would also like the program to be able to accept one parameter - the
> date in "5-MAR-2000 05:35:30.25" format, and have it create a
> symbol with the converted time in it that I could read in a DCL
> program.
> Thanks
> Rich
>
Here is an example in PL/I for setting symbol,
which you can readily translate to C

http://ftp.kednos.com/pli_examples/0091aacc-e97d5300-1c0069.html

and here for passing argument

http://ftp.kednos.com/pli_examples/0094d650-7f755220-1c01e7.html
0
Reply tom284 (1837) 11/18/2005 3:13:48 PM

In article <1132325401.896557.29530@g43g2000cwa.googlegroups.com>,
	"RJDurkee" <RJDurkee@yahoo.com> writes:
> I get the following error when compiling the program snippet listed
> above:
> 
> strcpy("5-MAR-2000 05:35:30.25",date_char);
>   .......^
> %CC-E-CLOSEPAREN, Missing ")".
> 
> I am using Dec CC.
> I would also like the program to be able to accept one parameter - the
> date in "5-MAR-2000 05:35:30.25" format, and have it create a
> symbol with the converted time in it that I could read in a DCL
> program.

Well, right off the bat, you have the source and destination reversed.
Secondly, you should be using strncpy() as it is always safer.  And
don't forget to allow for the \0 when you define the size of the
destination.

I do have to admit that the error message doesn't seem to make sense,
but I would need to see more of the output before deciding.  It could
actually be caused by an earlier error.

bill


-- 
Bill Gunshannon          |  de-moc-ra-cy (di mok' ra see) n.  Three wolves
bill@cs.scranton.edu     |  and a sheep voting on what's for dinner.
University of Scranton   |
Scranton, Pennsylvania   |         #include <std.disclaimer.h>   
0
Reply bill125 (2406) 11/18/2005 4:19:21 PM

Here is the source I was using. We have the Dec C compiler. I know
nothing about C, except that I don't think I like it.

#include <descrip>
#include <string.h>

char date_char[24];
unsigned int date_bin[2] ;
int status;

$DESCRIPTOR(date_char_desc,"dummy");
strncpy()(date_char,"5-MAR-2000 05:35:30.25");
date_char_desc.dsc$w_length = strlen(date_char);
date_char_desc.dsc$a_pointer = date_char;

status = SYS$BINTIM(&date_char_desc, &date_bin[0]); 


Rich

0
Reply RJDurkee (14) 11/18/2005 6:46:27 PM

In article <1132339587.441638.143870@f14g2000cwb.googlegroups.com>, "RJDurkee" <RJDurkee@yahoo.com> writes:
> Here is the source I was using. We have the Dec C compiler. I know
> nothing about C, except that I don't think I like it.
                               ------------------------


 Hail Brother! Well met!

--

Lee K. Gleason N5ZMR
Control-G Consultants
lgleason@houston.rr.com

0
Reply gleason (14) 11/18/2005 7:17:35 PM

RJDurkee wrote:
> 

> I would also like the program to be able to accept one parameter - the
> date in "5-MAR-2000 05:35:30.25" format, and have it create a
> symbol with the converted time in it that I could read in a DCL
> program.

Will this do? Alpha only. It converts the date in local DCL symbol
BINTIM_IN and formats into symbol BINTIM_OUT, e.g.

$ bintim_in = "5-MAR-2000 05:35:30.25"
$ r bintim
$ sh sym bintim_*
  BINTIM_IN = "5-MAR-2000 05:35:30.25"
  BINTIM_OUT = "44589513302500000"

/* BINTIM.C */

#include <descrip.h>
#include <starlet.h>
#include <lib$routines.h>
#include <stsdef.h>
#include <libclidef>

int main()
{
        int s;
        char b[40];
        long long q;
        long sym_type = LIB$K_CLI_LOCAL_SYM;
        $DESCRIPTOR(d, b);
        $DESCRIPTOR(sym_in, "BINTIM_IN");
        $DESCRIPTOR(sym_out, "BINTIM_OUT");
        $DESCRIPTOR(q_fao, "!SQ");

        s = lib$get_symbol(&sym_in, &d, &d.dsc$w_length, &sym_type);
        if (!$VMS_STATUS_SUCCESS(s)) sys$exit(s);

        s = sys$bintim(&d, &q);
        if (!$VMS_STATUS_SUCCESS(s)) sys$exit(s);

        d.dsc$w_length = sizeof(b);
        s = sys$fao(&q_fao, &d.dsc$w_length, &d, q);
        if (!$VMS_STATUS_SUCCESS(s)) sys$exit(s);

        s = lib$set_symbol(&sym_out, &d, &sym_type);
        sys$exit(s);

}

0
Reply burley.not-this (87) 11/18/2005 7:26:33 PM

In article <1132339587.441638.143870@f14g2000cwb.googlegroups.com>, "RJDurkee" <RJDurkee@yahoo.com> writes:
> Here is the source I was using. We have the Dec C compiler. I know
> nothing about C, except that I don't think I like it.

Here is some fixed up source

You were missing a main program declaration, had extra parens in
strncpy and missed the third parameter to strncpy.  And you weren't
checking your return status on the SYS$BINTIM call.

#include <descrip>
#include <string.h>
#include <stdio>

main() {

char date_char[24];
unsigned int date_bin[2] ;
int status;

$DESCRIPTOR(date_char_desc,"dummy");
strncpy(date_char,"5-MAR-2000 05:35:30.25",sizeof(date_char));
date_char_desc.dsc$w_length = strlen(date_char);
date_char_desc.dsc$a_pointer = date_char;

status = SYS$BINTIM(&date_char_desc, &date_bin[0]); 
printf ("%d\n", status );

}
0
Reply briggs3 (572) 11/18/2005 7:27:26 PM

I get the following error when I compile the above program -


        sys$exit(s);
     ....................^
%CC-E-BADSTMT, Invalid statement.at line number 37

        $DESCRIPTOR(d, b);
 ........^
%CC-W-ADDRCONSTEXT, In the initializer for d.dsc$a_pointer, "b" does
not have a constant address, but occurs in a context that requires an
address constant.  This is an extension of the language.at line number
17

I told you I didn't know anything about C - not even enough to figure
out how to correct these simple errors. I did, however, change this
line:

long long q;

to

long q;

As I was getting an error on the original code.

Thanks,
Rich

0
Reply RJDurkee (14) 11/21/2005 3:28:05 PM

RJDurkee wrote:
> 
> I get the following error when I compile the above program -
> 
>         sys$exit(s);
>      ....................^
> %CC-E-BADSTMT, Invalid statement.at line number 37

Looks suspiciously like something got lost when you copied it. If you're
using Google then use show options + show original and copy from there.


>         $DESCRIPTOR(d, b);
>  ........^
> %CC-W-ADDRCONSTEXT, In the initializer for d.dsc$a_pointer, "b" does
> not have a constant address, but occurs in a context that requires an
> address constant.  This is an extension of the language.at line number
> 17

I have to CC/WARNING=ENABLE=ALL or CC/STANDARD=PORTABLE to raise that
warning, and even then it's an informational. It would help to know
what compiler version you're using and what command/qualifiers you
tried (and if you have a symbol set-up for CC).


> I told you I didn't know anything about C - not even enough to figure
> out how to correct these simple errors. I did, however, change this
> line:
> 
> long long q;
> 
> to
> 
> long q;
> 
> As I was getting an error on the original code.

It would help to know what error. I'd guess it was %CC-W-TYPECONFLICT
and that you're using a VAX ?

0
Reply burley.not-this (87) 11/21/2005 11:29:42 PM

23 Replies
38 Views

(page loaded in 0.304 seconds)


Reply: