scramble.c

来自「C.Game.Programming.For.Dummies.原码」· C语言 代码 · 共 44 行

C
44
字号
#include <stdio.h>
#include <ctype.h>

void rot13(char *string);

void main()
{
    char phrase[] = "A pig fell in the mud.";

    printf("The phrase is:\n");
    puts(phrase);

    rot13(phrase);      //rot13 the phrase

    printf("The scrambled phrase is:\n");
    puts(phrase);

    rot13(phrase);      //rot13 it again

    printf("And unscrambled:\n");
    puts(phrase);

}

void rot13(char *string)
{
    int count = 0;
    char c = '!';       //initialize c

    while(c)
    {
        c = string[count];
        if(isalpha(c))
        {
            if(toupper(c)>='A' && toupper(c)<='M')
                c+=13;
            else
                c-=13;
        }
        string[count] = c;
        count++;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?