| | |
Rot 13 Help
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 0
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
Can some one help me out please
C Syntax (Toggle Plain Text)
#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; }
0
#2 33 Days Ago
while((c = getchar())!= EOF) "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 0
0
#3 32 Days Ago
•
•
•
•
And what does your function return for non-alpha input?while((c = getchar())!= EOF)
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; 32 Days Ago at 7:46 pm.
0
#4 32 Days Ago
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 0
0
#5 32 Days Ago
I put that in.
my new code looks like this
my new code looks like this
C Syntax (Toggle Plain Text)
#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; }
![]() |
Other Threads in the C Forum
- Previous Thread: factorial series
- Next Thread: Remowing white spaces + separating sentences
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop initialization input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list lists locate looping lowest matrix meter microsoft number oddnumber opendocumentformat openwebfoundation overwrite owf pdf pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






