- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Re: help in C
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 08:06 AM
03-24-2009 08:06 AM
help in C
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 08:40 AM
03-24-2009 08:40 AM
Re: help in C
$ cc x
$ link x
$ run x
hi
hi
$ type x.c
#include
main()
{
char foo[255];
gets( foo );
printf( foo );
return 0;
}
$
The above code runs and does exactly what you've asked for, but it's not particularly secure nor entirely reliable. The gets call has vulnerabilities.
I've posted a far larger example C program (that does this prompting, and a whole lot more) in the newuser code in the zip archive available available via:
http://64.223.189.234/node/1135
The OpenVMS C manuals and the OpenVMS programming concepts manuals (all of which are required reading here) are available at:
http://www.hp.com/go/openvms/doc
The C manuals and the Programming Concepts manual introduce you to the language and to programming C on OpenVMS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 08:45 AM
03-24-2009 08:45 AM
Re: help in C
I am sorry i think i explained it wrong, i dont want to input a string from command line but i want to be able to pass an argument to a procedure say x("test string")
and the program should print the string ?
thanks for help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 08:49 AM
03-24-2009 08:49 AM
Re: help in C
#include
void main ()
{
while (putchar (getchar ()) != EOF)
{}
}
^Z
$ cc demo
$ link demo
$ run demo
the quick brown fox jumps over the lazy dog!
the quick brown fox jumps over the laxy dog!
^Z
Figuring out how to get rid of the y-umlaut at the end is left as an exercise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 08:54 AM
03-24-2009 08:54 AM
Re: help in C
SUNNY2$ type snmp.c
#include
#include
int main( char *msg)
{
int sts;
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\" \"msg\"";
printf( " cmd: >%s<.\n", cmd);
sts = system( cmd);
printf( " sts = %%x%08x.\n", sts);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 09:02 AM
03-24-2009 09:02 AM
Re: help in C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 09:04 AM
03-24-2009 09:04 AM
Re: help in C
$ cc demo
$ link demo
$ run demo
Neither my nor Hoff's programs accepted input from the command line in that sense.
You say you want to "pass an argument to a procedure".
Do you mean like a function call? For example the printf function call:
printf ("test string\n");
Or you want to write a function that accepts a string argument and sends it to printf?
Or do you want to write a program that prints strings from the command line as in
$ demo "test string"
test string
?
In the latter case, refer to the DECC Language Reference Manual "Passing Arguments to the main Function", which is section 5.6.3 in the very old copy that I have.
You can find the DECC documentation in the usual places on the HP VMS documentation web site.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 09:18 AM
03-24-2009 09:18 AM
Re: help in C
so from command prompt i should be able to do this
$sndsnmp :== $sys$login:snmp.exe
$sndsnmp "test msg"
$sndsnmp "another test"
run snmp.exe "test msg" and the prog should replace the 'msg' value in the program with "test msg" , do you know what iam saying ?
let me know otherwise i will explain further
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 09:34 AM
03-24-2009 09:34 AM
Re: help in C
Probably your solution will include a statement something like this:
sprintf (cmd, "long string prefix %s", argv[1]);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 09:40 AM
03-24-2009 09:40 AM
Re: help in C
let me explain in a better way , I think what i need is very simple .
this is my working program now :
#include
#include
int main()
{
int sts;
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\" \"msg\"";
printf( " cmd: >%s<.\n", cmd);
sts = system( cmd);
printf( " sts = %%x%08x.\n", sts);
}
I run it like this :
SNDSNMP == "$SYS$LOGIN:SNMP.EXE"
SUNNY2$ sndsnmp
cmd: >mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 "D" "msg"<.
sts = %x00000001.
you see above its constructing a command with hard coded "msg" .
i want to be able to do this
$sndsnmp "test msg"
and it should construct the command
cmd: >mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 "D" "test msg"<.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 09:44 AM
03-24-2009 09:44 AM
Re: help in C
(the part marked with ^^^)
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\" \"msg\"";
^^^
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 10:03 AM
03-24-2009 10:03 AM
Re: help in C
#include
#include
main()
{
char *cmd ="write sys$output msg";
printf( " cmd: >%s<.\n", cmd);
}
SUNNY2$ xx :== $sys$login:x.exe
SUNNY2$ xx
cmd: >write sys$output msg<.
I want to be able to do this
main( argument)
{
char *cmd ="write sys$output
}
SUNNY2$ xx :== $sys$login:x.exe
SUNNY2$ xx "test msg"
cmd: >write sys$output test msg<.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 10:31 AM
03-24-2009 10:31 AM
Re: help in C
#include
#include
int main(int argc, char *argv[])
{
int sts;
char msg;
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\" \"*msg\"";
printf("program: %s\n",argv[1]);
/* printf( " cmd: >%s<.\n", cmd); */
sts = system( cmd);
printf( " sts = %%x%08x.\n", sts);
}
SUNNY2$ sndsnmp testing
program: testing
sts = %x00000001.
but I cant replace the 'msg' with the argument passed .. any ideas ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 10:42 AM
03-24-2009 10:42 AM
Re: help in C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 10:45 AM
03-24-2009 10:45 AM
Re: help in C
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\" \"*msg\"";
^^^^
how can i do this by sprintf ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 11:05 AM
03-24-2009 11:05 AM
Re: help in C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 11:10 AM
03-24-2009 11:10 AM
Re: help in C
tsprintf.c:
#include stdio
int main(int argc, char *argv[]) {
char cmd[256];
sprintf(cmd,"mcr sys$system:tcpip$snmp_trapsnd.exe"\
" 0.0 local 0 0 0 -h %s v2c"\
"1.3.6.1.6.3.1.1.4.1.0 \"D\" \"*msg\"",argv[1]);
printf(" %s\n",cmd); /show result*/
}
Test the program:
$ mcr []tsprintf 10.1.222.1
mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.1.222.1 v2c1.3.6.1.
6.3.1.1.4.1.0 "D" "*msg"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 11:38 AM
03-24-2009 11:38 AM
Re: help in C
> Sami, do You mean something like this ?
Probably more like this:
alp $ type snmp2.c
#include
#include
int main( int argc, char **argv)
{
int sts;
char cmd[ 1024];
sprintf( cmd, "mcr tcpip$snmp_trapsnd.exe\
1.3.6.1.6.3.1.1.4.1.0 local 0 0 0 -v2c -h 10.100.10.112 \"D\" \"%s\"",
argv[ 1]);
printf( " cmd: >%s<.\n", cmd);
sts = system( cmd);
printf( " sts = %%x%08x.\n", sts);
}
alp $ cc snmp2
alp $ link snmp2
alp $ mcr []snmp2 "my message text"
cmd: >mcr tcpip$snmp_trapsnd.exe 1.3.6.1.6.3.1.1.4.1.0 local 0 0 0 -v2c -h 10.1
00.10.112 "D" "my message text"<.
Invalid variable name OID syntax: D
Invalid variable list.
#snmp_trapsnd enterprise agent-address generic specific timeticks
[-v version] [-c community] [-h host] [-p port] [-tcp] {variable [type value]}
sts = %x00000001.
alp $
Looks as if the command itself may need a
little work.
The 'D' must be '"D"' to keep it upper-case
when snmp_trapsnd sees it.
Note that no one is checking to see if you
really have a command-line argument (argc >
1), so it'll behave badly if you don't
specify one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 12:21 PM
03-24-2009 12:21 PM
Re: help in C
marked 10.100.18.245 by ^^^^, so I assumed this IP address should be the variable argument.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2009 09:06 PM
03-24-2009 09:06 PM
Re: help in C
Cut and paste into (for example notepad), and you will see.
But what does this whole topic have to do with VMS?
Sami, if you need to learn C, this isn't the place to learn.
See Hoff's response to your question about snmp traps.
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1325393