Guest User

Untitled

a guest
Feb 15th, 2014
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. /*common.h*/
  2. #ifndef COMMON_H
  3. #define COMMON_H
  4. #include <stdlib.h>
  5.  
  6. /* constants: number of different characters, and
  7. first and last printable characters */
  8. #define NUM 128
  9. #define FIRST '!'
  10. #define LAST '~'
  11.  
  12. /* symbols for special characters, corresponding to codes 0 through FIRST-1 */
  13. char *symbols[] = {"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK",
  14. "BEL", "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", "DLE", "DC1",
  15. "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC",
  16. "FS", "GS", "RS", "US", "SPC" };
  17.  
  18. /* symbol for DEL character, code LAST+1 (same as NUM-1) */
  19. char *symbolDel = "DEL";
  20.  
  21. /* the following four functions must be used to print results */
  22.  
  23. /* use prHeader at the start to print header row (titles) */
  24. void prHeader(FILE *out) {
  25. fprintf(out, "Code\tChar\tCount\n----\t----\t-----\n");
  26. }
  27.  
  28. /* use prCountStr to print count for one of the special symbols */
  29. void prCountStr(FILE *out, int code, char *str, int count) {
  30. fprintf(out, "%3d\t%s\t%5d\n", code, str, count);
  31. }
  32.  
  33. /* use prCountChr to print count for one of the printable characters */
  34. void prCountChr(FILE *out, int code, char chr, int count) {
  35. fprintf(out, "%3d\t%c\t%5d\n", code, chr, count);
  36. }
  37.  
  38. /* use prTotal at the end to print total character count */
  39. void prTotal(FILE *out, int count) {
  40. fprintf(out, "\t\t-----\nTotal\t\t%5d\n", count);
  41. }
  42.  
  43. /* use the following three macros to print error messages for part 2
  44. {
  45. Beware: each macro executes two statements.
  46. }
  47. ignore these macros for part 1 */
  48.  
  49. /* use BADFILE(name) to exit if a file (name) cannot be opened */
  50. #define BADFILE(name) fprintf(stderr, "bad file: %s\n", (name)); \
  51. exit(1);
  52.  
  53. /* use BADOPTION(op) if an invalid option (not '-o') is on command line */
  54. #define BADOPTION(op) fprintf(stderr, "bad option: %s\n", (op)); \
  55. exit(2);
  56.  
  57. /* use MISSING (without parens) if output filename is missing */
  58. #define MISSING fprintf(stderr, "missing output file\n"); \
  59. exit(3);
  60.  
  61.  
  62. #endif
  63.  
  64.  
  65.  
  66.  
  67.  
  68. #include <stdio.h>
  69. #include "common.h"
  70.  
  71.  
  72. int main(int argc, char *argv[]) {
  73.  
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment