Skip to content

Instantly share code, notes, and snippets.

@dce
Created September 20, 2012 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dce/3757584 to your computer and use it in GitHub Desktop.
Save dce/3757584 to your computer and use it in GitHub Desktop.

encode.c

Simple exercise for learning C:

  • Reads text from STDIN
  • By default, rotates all text by one character ("abc" => "bcd")
  • Prints to STDOUT
  • If the "-n [number]" flag is supplied, rotate by that many characters
  • If the "-d" (decode) flag is supplied, rotate in the opposite direction
  • If the "-f [filename]" flag is supplied, read from that file rather than STDIN
@dce
Copy link
Author

dce commented Sep 20, 2012

Extra credit:

  • Handle invalid paths gracefully.
  • Handle lack of file and STDIN gracefully.

@dce
Copy link
Author

dce commented Sep 20, 2012

Actually, that second EC might be impossible, just based on the way STDIN works (e.g. run cat by itself -- it just hangs).

@dce
Copy link
Author

dce commented Sep 20, 2012

Extra credit: make the program write to STDOUT immediately instead of waiting for newlines (e.g. to pipe in the result of tail -f").

@reagent
Copy link

reagent commented Sep 22, 2012

What should the behavior be when supplying uppercase characters? Up to the implementer?

@dce
Copy link
Author

dce commented Sep 24, 2012

Yeah, I'd say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment