CS 1713 Section 3, Spring 1997
Assignment 1: Type-in Program, News, and E-mail
For this assignment, you will:
- Type in and compile the C program at the end of this assignment.
The program asks the user to enter his or her name, then prints the
ASCII value for each character in the name.
Use vi or your favorite editor to enter the program, calling
it name.c, then
compile it on runner using the following command:
cc -o name name.c
- Run the program, entering your name at the prompt. Run the program
again, this time redirecting output to a file called name.out.
You can redirect output by running name like this:
name > name.out
This time, you won't be able to see the prompt, since it is going to the
output file name.out, but enter your name anyway.
- Look at the output file using the cat command:
cat name.out
- Send the instructor the output file (not the program) through e-mail:
Mail -s "CS1713 Assignment 1" djimenez@ringer.cs.utsa.edu < name.out
The less-than sign means input to the Mail program is being
redirected from the keyboard to the file name.out.
You must run this command from your account on runner.
- Again using vi (or your favorite text editor), write a report
on your experiences with this assignment; this will be your first weekly
progress report. Include in the report the following:
- Any problems you had entering the program.
- The output of the program (use :r name.out from vi).
- A summary of what you learned in class during the first week.
- A question you have about computer science.
Note the last two items should always be included with your weekly progress
report.
- Post the report to the UTSA newsgroup
utsa.cs.1713-3.d using either Pnews or the f
command from trn. Don't try posting from lynx or Netscape.
This assignment is due at midnight on Wednesday, January 22, 1997.
Here is the program you are to type in. Substitute your name where
it says Your Name.
#include <stdio.h>
#include <unistd.h>
/*
* Name: Your Name
*
* Class: CS 1713 section 3
*
* Purpose: This program reads your name from standard input and prints
* the decimal ASCII (American Standard Code for Information Interchange)
* value for each letter.
*
*/
void print_ascii (char *);
/*
* main function
*
* This is the main program. It asks for your name, reads it into an array
* of characters, and calls the `print_ascii' function to print the ASCII
* values.
*/
int main (int argc, char *argv[]) {
char name[100];
/* prompt for the name */
printf ("Enter your name: ");
/* read the name into the string `name' */
gets (name);
/* print the name and ASCII values */
printf ("Your name is: %s\n", name);
printf ("The ASCII values are: ");
print_ascii (name);
/* leave the program with exit code zero */
exit (0);
}
/*
* print_ascii (char *)
*
* This function accepts a string and prints the ASCII value of each
* character, then prints a newline
*/
void print_ascii (char *s) {
int i, a;
/* let i start at zero and continue until the i'th character
* in s is null, i.e., the end of the string
*/
for (i=0; s[i]; i++) {
/* convert s[i] to an integer and print it,
* followed by a space
*/
a = (int) s[i];
printf ("%d ", a);
}
/* print a newline */
printf ("\n");
}