Due: 12:00 Noon Tue Oct 8
You are to create a number of files, as directed below, and then submit them electronically on host lectura.cs.arizona.edu using the command
Please follow the directions below carefully: submissions that don't follow directions will be penalized heavily.
Note: As before, your programs should compile with no errors or warnings when compiled with gcc -Wall. Moreover, each program should exit with a status of 0 if execution proceeds normally, and a status of -1 if any sort of error occurs.
For this assignment, your programs should read all their inputs using the myIO library mentioned below. Furthermore, while you can declare space for buffers etc. as arrays of char, your code should process strings using pointers, not as indexed arrays.
Write a C program, in a file mywc.c, that reads input from stdin until end-of-file is encountered, then prints out, on stdout, the following:
nLines nWords nCharswhere nLines is the number of lines read from the input; nWords is the number of words; and nChars is the number of characters read.
For this problem, a word is defined as follows. Call a character ch readable if (i) ch is printable; and (ii) ch is not whitespace. I.e., ch is readable if
isprint(ch) && ! isspace(ch)See the man pages for these functions for details. Then, a word w satisfies the following criteria:
In the output generated, each adjacent pair of numbers should be separated by a single space, e.g., when printed using
printf("%d %d %d\n", nLines, nWords, nChars);
Write a C program, in a file mysort.c, that reads input from stdin until end-of-file is encountered, then prints out, on stdout, the input lines in sorted order. All of the input lines, including empty and blank lines, should be printed out, i.e., the number of lines printed should equal the number of lines read in.
For sorting, use the ordering between lines given by the string library function strcmp: given two strings s1 and s2, s1 comes before (i.e., is ``less than'') s2 if
strcmp(s1, s2) < 0.
Write a C program, in a file myspell.c, that behaves as follows.
/home/cs352/FALL02/hw4_stuff/WORDS
For this problem, a word is a sequence of letters: your program should ignore non-letter characters in the input. Your program should be case-insensitive, i.e., it should match words in the input with words in the dictionary, regardless of upper/lower case differences between them. Note that both the input (from stdin) and the dictionary (from the file specified above) can contain a mix of upper and lower case letters.
You may assume that a word is at most 64 characters long.
Hint: You should be able to get strcmp( ) to do all the work of checking whether an input word is in the dictionary. How would you set things up so that a call to strcmp( ) will do what you need it to do? (Don't forget the '\n' character at the end of each line of text read in: this includes the words in the dictionary file as well.)