/* 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"); }
gcc -o hello hello.c (gcc is the C Compiler) hello (run the program) hello, world (resulting output)
/* 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"); }
args "This is number 1" and this is 2 to 7
This time the output should be re-directed to a file the line printer instead of your terminal.args "This is number 1" and this is 2 to 7 | lpr
Place the lab in the instructor hand-in box in BUS R6E, the "terminal room".Your-Name Lab 4.7: ``C'' TABER CSC135