PROGRAM 1
# program name: myscript # student name: anthony f. ortiz # assignment #: 1 # class: cs3560 # quarter: spring 97 # date program completed: 4/15/97 # date program compiled: 4/15/97 # version of compiler/interpreter: csuh c compiler for cutcol # # this script prompts the user to input a single character abbreviation # for the desired terminal and or emulator being used. if the response is an # h then my script will print help in the form of a list of terminal types # and letter abbreviations on the crt. if the reponse is not a legal # terminal type abbreviation then the program displays "terminal type # unknown, try again" and allows the user to reinput a letter. if the # response is a legal terminal abbreviation, then the program prints a # message "terminal now set to "terminal" with public write permission off" # and sets the term variable in the shell. set done = "t" while ($done == "t") echo -n "terminal (h = help): " set termtype = $< if ($termtype == "h") then cutcol 1 29 myout * will take "myfile" as the input stream and extract columns 12-34 * to a file called myout. */ #include main( argc,argv,envp) int argc; char *argv[], *envp[]; { int number_left, number_right, count; int ch=0; if(argc<=2) { /* if user forgets usage, then the template is provided. */ printf ("\nUsage %s \n",argv[0]); exit(); } number_left =atoi(&argv[1][0]); /* atoi convert string to integer. */ number_right=atoi(&argv[2][0]); if (number_left >= number_right || number_left<1 || number_right<1) { printf ("invalid values\n"); exit(); } while (ch!=EOF) { /* do while not end of file (^D from terminal). */ /* first run up to the left column (eat the characters). */ for(count=1; count<=number_left && (ch=getchar())!='\n' && ch!=EOF; count++); if (ch!='\n' && ch!=EOF) { putchar(ch); /* now print up to and including the right column. */ for( ; count<=number_right && (ch=getchar())!='\n' && ch!=EOF; count++) putchar(ch); if (ch!='\n' && ch!=EOF) /* eat rest of line. */ while ((ch=getchar())!='\n' && ch!=EOF); } putchar('\n'); } /* end while. */ } /* end of main. */ # outfile: prog1.out h terminal (h = help):
BACK TO CS3560 PAGE.