Prev Up Next
Go backward to 4.15 VAX Variables -- #2
Go up to 4 Labs
Go forward to 4.17 VAX File Protection

4.16 The "C" Language

C is a systems programming language. The UNIX operating system is mostly written in C. Many compilers are written in C. It is also a very portable language. There are C compilers available on most computer systems, from the very small (cross compilers are available for embedded systems) to the largest. For super-computers there is a group working on a vector version of C. C is also one of the languages in IBM's Systems Application Architecture (SAA). If written in IBM's dialect of C they assure customers that the program will run under OS/2, OS/400, VM, and MVS. This lab is an introduction to traditional C. There is a related language called C++. It is an object oriented language.
  1. Using the text editor, create the following "C" program. This program "translated" is a good first choice whenever you are faced with a new language or a new system. It gets you away from the problems of the language and lets you look at the procedural difficulties of getting a simple program to work. Please name the source file hello.c.
    /* Program to print "hello, world"                  */ 
    /* L Taber   October 13, 1992   PCC                 */
    /* Kernighan & Richie "The C Programming Language"  */ 
    /* Copyright 1978  page 6                           */
    
    #include <stdio.h> 
    
    main() 
    { 
    printf("hello, world\n"); 
    }
    
  2. Compile and run the program:
     
    $ cc hello                    (cc is the C Compiler) 
    $ link hello
    $ run hello                   (run the program) 
    
    
    hello, world                  (resulting output)
    
  3. The next program looks at the arguments and environment variables available to the program. Most operating systems pass some information to programs being run. Arguments are placed on the command line. The environment is information about system and the user running the program. Create the following C program, please name the source file args.c.
    /* Program to print arguments to a program    */
    /* L Taber   March 28, 1993   PCC             */
    
    #include <stdio.h>
    
    main(argc, argv, env)
    int argc;
    char * argv[ ];
    char * env[ ];
    
    {
    int i;
    
    /* Print number of arguments and the first argument */
    
    printf("argc = %d   File name = %s\n", argc, argv[0]);
    
    /* Print all remaining arguments - if any */
    
    for ( i=1; i<argc; i++) 
        printf(" arg[%d] = %s \n" ,i,argv[i]);
    printf("\n");
    
    /* Print the environment - if any */
    
    for ( i=0; env[i] != NULL; i++) 
        printf(" env[%d] = %s\n" ,i,env[i]);
    printf("\n");
    
    }
    
  4. Compile ( /list ), link, and test the program. See part in this section. Note that when you run the program, you do NOT use the RUN command. The symbol definition lets you run it without saying RUN. If you use the RUN command you will not pass any arguments.
  5. A symbol has been defined in 135login.com for you. It is so that you can pass arguments to args.exe. Its definition looks as follows:
     
    $ args :== $sys$login:args 'p1' 'p2' 'p3' ... 'p8'
    
  6. ASSIGN SYS$OUTPUT as a user mode logical name to C.OUT.
    $ DEFINE /USER_MODE SYS$OUTPUT C.OUT
    
  7. Run the program again. Passing arguments to the program as shown:
    $ args "This is number 1" and this is 2 to 7
    
    This time the output should be re-directed to a file (C.OUT), instead of your terminal. Redirect the output to your terminal with:
    $ DEASSIGN SYS$OUTPUT
    
Print and turn in a copy of C.OUT and a listing of ARGS.C marked with:
Your-Name
Lab 4.16: VAX C
TABER CSC135
Place the lab in the instructor hand-in box in BUS R6E, the "terminal room".
Instructor: ltaber@pima.edu** Red's Home page** The Pima College Site

Prev Up Next