rmerchan 0 Newbie Poster

When I try to scan in the selection the program will not then let me scan in the string to encrypt. If i take the selection function out then the program does exactly what it is suppose to do. Any help would be great.

Thanks alot Ryan

# include<stdio.h>
# include<string.h>

# define SIZE 49   //number of characters
# define MINCAP 65 //minumum Uppercase value
# define MIDCAP 78 //middle Uppercase value
# define MINLOW 97 //minumum lowercase value
# define MIDLOW 110//middle lowercase value
# define MAXCAP 90 //maximum Uppercase value
# define MAXLOW 122//maximum lowercase value

int printmenu();
void rot13(char []);

int main()
{
  char str1[SIZE]; //character string
  int selection;

     selection = printmenu();

     printf("Enter the string: ");
     gets(str1);

     rot13(str1);

   printf("The result is: %s\n", str1);
   return(0);
}
/****************************************************
*
*     Function Information
*
*     Name of Function:rot13
*
*     Programmer's Name:Ryan Merchant
*
*     Function Return Type:int
*
*     Parameters:void
*
*     Function Description:This function takes a string and
*
****************************************************/
int printmenu()
{
  int selection = 0;

  printf("Welcome to Project 4!\n");
  printf("1. Encrypt using ROT 13\n");
  printf("2. Decrypt using ROT 13\n");
  printf("3. Encrypt using Boiler Key\n");
  printf("4. Decrypt using Boiler Key\n");
  printf("5. Exit the Program\n\n");
  printf("Enter selection now:\n");
  scanf("%d", &selection);

  return(selection);
}
/****************************************************
*
*     Function Information
*
*     Name of Function:rot13
*
*     Programmer's Name:Ryan Merchant
*
*     Function Return Type:void
*
*     Parameters:char []
*
*     Function Description:This function takes a string and
*       encrypts or decrypts the string using ROT13 to raise or
*       lower the character by 13. A->N,a->n,N->A,a->n, and the
*       same is true for lower case variables.
*
****************************************************/
void rot13(char str1[])
{
  int i; //loop control variable


  for(i = 0; i < strlen(str1); i++)
  {
    if ((str1[i] >= MINCAP && str1[i] < MIDCAP) || (str1[i]
>= MINLOW && str1[i] < MIDLOW))
    {
      str1[i] = str1[i] + 13;
    }
    else if ((str1[i] >= MIDCAP && str1[i] <= MAXCAP) ||
(str1[i] >= MIDLOW && str1[i] <= MAXLOW))
    {
      str1[i] = str1[i] - 13;
    }
    else
    {
      i = i;
    }
  }
}

:cheesy: :cheesy: :cheesy:

Dave Sinkula commented: Use code tags. +0