Objective In this lab, you will demonstrate a competency in the \"C\" programmin
ID: 3649247 • Letter: O
Question
ObjectiveIn this lab, you will demonstrate a competency in the "C" programming language. Competency in C will be required for future success in this course.
Skills that you must acquire before attempting this lab
Familiarity with the C programming language
How to run a text editor (such as emacs)
You will demonstrate mastery of
Arrays and pointers
memory allocation
Separate compilations and linking
Writing a simple Makefile
Assignment
Write a tokenizer function mytoc() in a file called mytoc.c. Mytoc()'s signature must also be provided in a "header" file named mytoc.h.
Write file named test.c containing a test program that includes the header file mytoc.h. The behavior of this program is described below.
Write a Makefile that compiles the two source files and links them to build a functional test program named "test".
A description of mytoc:
In general, tokenizers partition a character string into individual tokens (words) separated by reserved "delimiter characters".? In this case, the delimiter character is the space character and tokens contain any characters other than space characters.
Your function "mytoc" should have the following signature:
char ** mytoc(char *)
A call to mytoc() should return a freshly allocated null-terminated array of pointers to freshly allocated strings containing each "token" from the input string. The input string can be of any length, and should not be modified. The vector returned by mytoc() and the strings referenced by it, should all be allocated using malloc or calloc (so that it would be appropriate to free() them). Finally, these dynamically allocated blocks of memory should not be larger (or smaller) than required.
For example, a call to mytoc("hello world") should return the address of an array containing:
{"hello", "world", (char*)0}
Other than malloc/calloc/free, your implementation of mytoc should only call functions written by you. In particular, calls to functions whose prototypes are in "string.h" such as "strtok()" are prohibited.
Compiling your program:
A "C" source file "foo.c" can be compiled to an object file
foo.o on unix or
foo.obj on windows/dos
by the command "cc -c foo.c" The object files "foo.o" and "goo.o" can be compiled to an executable "goo" by the command "cc -o foo foo.o goo.o". Note that on your system, the C compiler (normally named "cc") may instead be named "gcc". You can learn more about the options to cc or gcc by "asking the manual" by typing "man " where topic might be "cc" or "gcc". While executable files under unix can have any name whatsoever, on windows systems, executable files have the extension ".exe."
What is a library and how to link?
C is an extremely small language that (for example) provides no I/O, string handling or math functions. Most distributions of C provide this functionality through a rich set of libraries. For example, the standard library, often called "libc" contains object files "printf.o" and "scanf.o" which implement the familiar functions "printf" and "scanf". To prepare the compiler's "object" file for execution, it must be "linked" with object files providing all referenced functions. By when linking objects into executables, "cc" first includes all object files on the command line, and then searches "libc" for objects defining variables or functions referenced but not defined by these object files.
Make
The make utility is a program that can be told of the dependency of compiled files from their source. For example, in your program:
Output Input Command to generate output file
test test.o, and mytoc.o cc -o test test.o mytoc.o
mytoc.o mytoc.c cc -c mytoc.c
test.o test.c and mytoc.h cc -c test.c
Makefiles (named "Makefile") contain production rules of the form
output file: source files
command to run if any source file is newer than the output file
By default, make will attempt to build the first output file listed in the Makefile.
Your test program
Your test program should, in a loop:
print a prompt "$ "
read a string typed at the keyboard.
break the string into tokens and print them out, one to a line.
I strongly prefer that you use the system call write() rather than printf() to emit the "$ " prompt. If you use "printf" to print the string, you will need to call fflush(stdout) to force the prompt to be printed. Don't forget to "#include "!
Questions about this lab should be sent to the course mailing list.
Explanation / Answer
Emacs is a family of text editors, characterized by their extensibility. One manual describes it as "the extensible, customizable, self-documenting, real-time display editor." Development began in the mid-1970s and continues actively as of 2012. The most popular (and most ported) version of Emacs is GNU Emacs, created by Stallman for the GNU Project.[8] Another version in common use, XEmacs, was forked from GNU Emacs in 1991. XEmacs has remained mostly compatible and continues to use Emacs Lisp like GNU Emacs. An array is a systematic arrangement of objects, usually in rows and columns. Generally, a collection of data items that can be selected by indices computed at run-time, including: Array data structure, an arrangement of items at equally spaced addresses in computer memory Array data type, used in a programming language to specify a variable that can be indexed Associative array, an abstract data structure model that generalizes arrays to arbitrary indices. Pointer (computer programming), a data type used in programming. Memory management is the act of managing computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed. This is critical to the computer system. Several methods have been devised that increase the effectiveness of memory management. Virtual memory systems separate the memory addresses used by a process from actual physical addresses, allowing separation of processes and increasing the effectively available amount of RAM using paging or swapping to secondary storage. The quality of the virtual memory manager can have an extensive effect on overall system performance.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.