Match Lab for u0000000

The goal of this lab is to give you some practice with C on a problem that is algorithmically straightforward but difficult to get right on a first try. With any luck, you'll have a bug along the way, and then you get to practice using GDB.

Your task is to implement a program that takes command-line arguments and checks whether each argument matches a particular pattern. The pattern to check is determined by a command-line flag: -a, -b, or -c, where the default mode is -a. The patterns for each flag are described below.

By default, your program should print “yes” for each matching argument and “no” for each non-matching argument, each on a separate line. If the -t flag is provided, then your program should instead print nothing for non-matching argument and it should print a converted value for each matching argument. Each pattern mode has an associated conversion, as described below.

At most one of -a, -b, or -c will be provided. A -t flag can be provided before or after any of -a, -b, and -c. All flags (i.e,. up to two of them) precede other command-line arguments. A non-flag argument never starts with -. All arguments are in ASCII.

See the end of this page for example command-line uses of your program. Neither the examples there nor the examples for indvidual patterns are meant to be exhaustive.

Constraints: Your implementation must not depend on any libraries other than the standard C library. Also, it must not use multiplication, division, or modulo operators. (Bitwise operations offer alternatives to those operations.) You should hand in one matchlab.c file so that gcc -O2 -o matchlab matchlab.c on a CADE lab machine builds your program as matchlab. Hand in via Canvas.

Important! Make sure the uID listed at the top of the page is correct, because this assignment (and its correct answer) is uID-specific.

Where the descriptions below say “even position” or “odd position”, counting is from 0, as in C. So, a first character is in an even position.

-a mode

Match a sequence of (with nothing else before or after) For matches, perform the following conversion: Example arguments that match, followed by their conversions: Example arguments that do not match:

-b mode

Match a sequence of (with nothing else before or after) For matches, perform the following conversion: Example arguments that match, followed by their conversions: Example arguments that do not match:

-c mode

Match a sequence of (with nothing else before or after) For matches, perform the following conversion: Example arguments that match, followed by their conversions: Example arguments that do not match:

Examples

Assuming that your program is created as ./matchlab, here are some example command-line uses (where “$” is a command-line prompt):

  $ ./matchlab cccccuuuH
  yes
  $ ./matchlab cccccccsssssssssECB
  no
  $ ./matchlab cccccuuuH cccccccsssssssssECB
  yes
  no
  $ ./matchlab -t cccccuuuH
  HHHHHHHHH
  $ ./matchlab -t cccccccsssssssssECB cccccuuuH
  HHHHHHHHH
  $ ./matchlab -t cccccuuuH cccccccccuuuF
  HHHHHHHHH
  FFFFFFFFFFFFF
  $ ./matchlab -t -b jjjjjjjjj505ooooooo55FFC
  jjjjjjjjj505ooooooo55EFEFC
  $ ./matchlab -c -t hh98qqqqqqq989898ACC
  hh98qqqqqqq989898ACC
  $ ./matchlab -c hh98qqqqqqq989898ACC
  yes