[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Outlines] [Labs] [Assignments] [Exams] [Examples] [Project]
These are some general notes on assignment 1.
A generally correct assignment received a B. If I felt that the overall design of your program was somewhat awkward, I gave you a B-. If I felt that there were particularly nice aspects of your program, I gave you a higher grade.
You may recall that there were a pair of lines in the original code on the order of
fgets(buf, sizeof(buf), stdin); buf[MAX_LINE-1] = '\0';
Why do we put the 0 character at the end of the string? If there
was no carriage return in the first MAX_LINE characters,
there is no 0 character to terminate the string. While this won't
cause a problem for send, it will cause a problem on the
other side when it goes to print. Now, I'm not sure why we get
sizeof(buf) characters rather than sizeof(buf)-1,
but that's a problem for another day.
A number of you wrote something like the following
int spew(int s, char *buf, int len)
{
while (fgets(buf, MAX_LINE, stdin)) {
...
} /* while we get lines. */
} /* spew */
buf and len parameters rather
than local variables.
if (!strcmp(a,b)) an awkward way to write
``if a and b are the same''. I prefer if(strcmp(a,b) == 0),
since it is marginally clearer.
#ifdef. For
example,
#ifdef EXPERIMENTAL /* These lines are unlikely to work. I've left them here to remind * myself never to try it again. */ yadda(); yadda(); yadda(); #endif
break to exit loops when there is no other
alternative. It's much harder to trace code that exits loops in
the middle.
For the first solution, I put everything into one file. The way in which
you run the executable determines whether it acts as a client or a server.
You can find that solution as
chat.c in the
course examples.
For the second solution, I used separate files.
chatserver.c
is the server.
chatclient.c is the client.
chatutils.c
contains the functions used by both server and client.
chat.h
defines shared functions and common constants.
Finally, the Makefile
describes how to build everything.
[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Outlines] [Labs] [Assignments] [Exams] [Examples] [Project]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Assignments/notes.01.html
Source text last modified Mon Feb 14 07:41:06 2000.
This page generated on Fri Feb 18 14:02:05 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu