I made a program that finds the ROT 13, but theres a little thing thats messing it up for me. Its supposed to find the ROT 13 of each character but when i run it, it gives me some funky character in return

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

int rot13(int c)
{
  if (c >= 'A' && c < 'N')
    {
      return c + 13;
    }
  if (c >= 'N' && c <= 'Z')
    {
      return c - 13;
    }
  if (c >= 'a' && c < 'n')
    {
      return c + 13;
    }
  if (c >= 'n' && c <= 'z')
    {
      return c - 13;
    }
 
}
int main(void)
{
  int c; 
  printf("Enter a character: ");
 
  while((c == getchar())!= EOF)
    { 
      char a = rot13(c);
      printf("%c", a);   
      c++;
    }
  return 0;
}

Can some one help me out please

while((c = getchar())!= EOF)

And what does your function return for non-alpha input?

It just returns the number
if I input 10, it returns 10
if I input ? it returns ?

This program is supposed to do only one of the characters
If i input Apple, its supposed to return N and nothing else

Edited 7 Years Ago by yasaswyg: n/a

I don't see that return c; line.

I put that in.

my new code looks like this

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


int rot13(int c)
{
  if (c >= 'A' && c < 'N')
    {
      return c + 13;
    }
  if (c >= 'N' && c <= 'Z')
    {
      return c - 13;
    }
  if (c >= 'a' && c < 'n')
    {
      return c + 13;
    }
  if (c >= 'n' && c <= 'z')
    {
      return c - 13;
    }
	return c;
}
int main(void)
{
  int c; 
  printf("ROT 13 Converter\n\nEnter a Character: ");
 
	while((c = getchar())!= EOF) 
	{ 
      char a = rot13(c);
      printf("%c", a);   
      c++;
    }
  return 0;
}
This article has been dead for over six months. Start a new discussion instead.