CSC 115.005/006 Sonoma State University Spring 2022
Scribbler 2
CSC 115.005/006:
Programming I
Scribbler 2
Instructor: Henry M. Walker

Lecturer, Sonoma State University
Professor Emeritus of Computer Science and Mathematics, Grinnell College


Course Home References Course Details: Syllabus, Schedule, Deadlines, Topic organization MyroC Documentation Project Scope/
Acknowledgments

Notes:

Practice with Elementary C, eSpeak, and Makefiles

Work Started in Class

Time saving Linux Capabilities

In the introduction to C lab, you edited, compiled, and ran a C program quarts.c. This part of the lab provides experience with several Linux capabilities that can simplify some parts of program development.

Autocompletion

  1. Try using "autocompletion" with quarts and quarts.c by typing

    gcc -o q followed by the TAB key
    

    You should find that when you press TAB the system completes the file name for you. In this case, both quarts and quarts.c are files in your directory, so the TAB completes q with the common prefix quarts, giving

    gcc -o quarts 
    

    Type q and the TAB key again:

    gcc -o quarts q followed by the TAB key
    

    Again, autocompletion gives

    gcc -o quarts quarts
    

    Type a period and the TAB, and autocompletion gives

    gcc -o quarts quarts.c
    
  2. This time, start the same as in the previous step, but hit the TAB key twice typing

    gcc -o q TAB TAB
    

    Describe what you see.

The Manual

  1. Use the man command to consult the online Linux manual (Note the q key is used to quit or exit man pages):

    1. What do the following command options mean? Note the ability to combine flags (or smash them together).

        cp -i
        ls -ltr
        mkdir -p
      
    2. Why does the cat command have the name "cat", which stands for "concatenate"?

    3. Use the man page for the C function sqrt to identify the parameters and return type for a collection of functions related to sqrt. Also, what "include" statement is needed for sqrt?

  2. The command man -k keyword lists commands that seem related to the given keyword. For example, to print a list of man pages that include the word "square" in the name or description fields, you could use "man -k square". Try this command to locate sqrt and to determine various commands related to the keyword "print".

eSpeak

In many applications, it is helpful to include speech synthesis within a C program. Although not perfect (actually far from perfect), the eSpeak package provides a simple way to instruct the workstation to talk, given specific text.

In order to limit interference with the work of others in the lab, use the volume controls on your workstation to set the volume at a moderate level.

The Linux/Mac OS directory with documentation for the eSpeak package contains a commentary, a header file, and two C programs as examples.

  1. As an example, program quarts-espeak.c provides some audible commentary to a program that converts quarts to liters.

    1. Load quarts-espeak.c into your browser, paste it into aquamacs, and save the file to your Desktop.
    2. To compile quarts-espeak.c, you must tell the gcc compiler where to find the eSpeakPackage. This is done by adding several pieces to the usual compile line:

      gcc -Wall -Wno-deprecated-declarations -std=gnu99 -leSpeakPackage quarts-espeak.c -o quarts-espeak
      
    3. Run the program with the expected name of the compiled program:

      ./quarts-espeak
      
  2. As an alternative approach to compiling this program,

    • Copy Makefile (if you have not copied this file to your Desktop previously).
    • Save the program to your account.

    Compile and run quarts-espeak.c using the make command:

    make quarts-espeak
    ./quarts-espeak
    
  3. The make command checks whether the current version of the file has already been compiled. If so, no compilation is needed. If not, the gcc command compiles the program as it normally does.

    1. Open quarts-espeak.c with the aquamacs editor.

    2. Change the program in some way (e.g., add a comment).

    3. Use make to compile the program:

      make quarts-espeak
      
    4. Use the same command to compile again the program (without changing it), and observe how make responds.

    5. Run quarts-espeak to check that it runs properly.

  4. Open quarts-espeak.c in an editor, and find the various eSpeak commands. Review the program with the following notes:

    • eSpeakConnect () sets up the eSpeak environment. As part of this activity, the synthesized voice is set randomly to a male or female voice.
    • eSpeakSetGender (parm) allows the parameter to be "female" or "male", and sets the corresponding voice characteristics.
    • eSpeakTalk ("text goes here") instructs eSpeak to create audio related to the text specified.
    • eSpeakDisconnect () cleans up the eSpeak environment. If this command is omitted, the workstation's speaker may hum for awhile after the program finishes.
  5. Modify quarts-espeak.c in several ways to explore the capabilities of this package.

  6. Now copy program eSpeakExample1.c to your account.

    1. Compile the program with make, and run it.
    2. Edit the program to reflect a short dialog between two people. Use the eSpeakSetGender function, so that one speaker speaks in a generally "male" sounding tone and the other speaker speaks in a generally "female" sounding tone. Once written, compile and run the program.

created 15 January 2014 by Henry M. Walker, based on earlier labs by
  • Henry M. Walker: 31 March 2008, 22 August 2011, 20 July 2012, 1 September 2013
  • Erik Opavsky and David Cowden: 18 July 2011
  • Erik Opavsky and Dilan Ustek: 21 September 2011
material reorganized, eSpeak added 15 January 2014 by Henry M. Walker
readings added 1 September 2014 by Henry M. Walker
Makefile added and lab reformatted and generalized 11 May 2016 by Henry M. Walker
revised for Sonoma State University 28 January 2022 by Henry M. Walker
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.