/* rotate the letters in a file by x places*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
   int	  letter, out, x, counter;
   FILE	*ifp, *ofp;
   
   if (argc != 3) {
      printf("\n%s%s%s\n\n", "Usage: ", argv[0], " infile  outfile");
      exit(1);
   }
   
   ifp = fopen(argv[1], "r");
   ofp = fopen(argv[2], "w");
   
   
  printf ("rotate by? ");
  scanf (" %d", &x);

  out = 0;
  counter = 0;

   while ((letter = getc(ifp)) != EOF)
   	if (letter >= '!' && letter <= '~') { 
	   out = (letter + x);
	   
	   if (out > '~') {
	     out = (out - ('~' - ('!' - 1)));
	   }
	   
	   if (((counter % 60) == 0) && (counter != 0)) {
	   fprintf(ofp, "\n");
	   }
	   
 	   fprintf(ofp, "%c", out);
	   counter++;
	}

   fclose(ifp);
   fclose(ofp);
   return 0;

}

