CS 1713 Section 1, Summer 1997
Assignment 1: Type-in Program, News, and E-mail

For this assignment, you will:

This assignment is due at midnight on Friday, June 6, 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");
}