943,965 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 595
  • C RSS
Nov 1st, 2009
0

Rot 13 Help

Expand Post »
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
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int rot13(int c)
  5. {
  6. if (c >= 'A' && c < 'N')
  7. {
  8. return c + 13;
  9. }
  10. if (c >= 'N' && c <= 'Z')
  11. {
  12. return c - 13;
  13. }
  14. if (c >= 'a' && c < 'n')
  15. {
  16. return c + 13;
  17. }
  18. if (c >= 'n' && c <= 'z')
  19. {
  20. return c - 13;
  21. }
  22.  
  23. }
  24. int main(void)
  25. {
  26. int c;
  27. printf("Enter a character: ");
  28.  
  29. while((c == getchar())!= EOF)
  30. {
  31. char a = rot13(c);
  32. printf("%c", a);
  33. c++;
  34. }
  35. return 0;
  36. }
Can some one help me out please
Reputation Points: 6
Solved Threads: 0
Light Poster
yasaswyg is offline Offline
43 posts
since Jul 2009
Nov 1st, 2009
0
Re: Rot 13 Help
while((c = getchar())!= EOF)
And what does your function return for non-alpha input?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 1st, 2009
0
Re: Rot 13 Help
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
Last edited by yasaswyg; Nov 1st, 2009 at 7:46 pm.
Reputation Points: 6
Solved Threads: 0
Light Poster
yasaswyg is offline Offline
43 posts
since Jul 2009
Nov 1st, 2009
0
Re: Rot 13 Help
Click to Expand / Collapse  Quote originally posted by yasaswyg ...
It just returns the number
if I input 10, it returns 10
if I input ? it returns ?
I don't see that return c; line.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 1st, 2009
0
Re: Rot 13 Help
I don't see that return c; line.
I put that in.

my new code looks like this
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. int rot13(int c)
  6. {
  7. if (c >= 'A' && c < 'N')
  8. {
  9. return c + 13;
  10. }
  11. if (c >= 'N' && c <= 'Z')
  12. {
  13. return c - 13;
  14. }
  15. if (c >= 'a' && c < 'n')
  16. {
  17. return c + 13;
  18. }
  19. if (c >= 'n' && c <= 'z')
  20. {
  21. return c - 13;
  22. }
  23. return c;
  24. }
  25. int main(void)
  26. {
  27. int c;
  28. printf("ROT 13 Converter\n\nEnter a Character: ");
  29.  
  30. while((c = getchar())!= EOF)
  31. {
  32. char a = rot13(c);
  33. printf("%c", a);
  34. c++;
  35. }
  36. return 0;
  37. }
Reputation Points: 6
Solved Threads: 0
Light Poster
yasaswyg is offline Offline
43 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: factorial series
Next Thread in C Forum Timeline: Remowing white spaces + separating sentences





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC