Rank 02 Level 0 - kevshouse/exam_quest GitHub Wiki

rotone.c and rot13.c

Think of this as a Lego brick.

#include <unistd.h>

void rotone(char *s)
{
    int        i;
    if (!s)
        return ;
    i = 0;
    while (s[i] != '\0')
    {
        (s[i] >= 'a' && s[i] <= 'z' || (s[i]  >= 'A' && s[i] <= 'Z'))
        {
             if (s[i] == 'z')
                 s[i] = 'a';
             else if (s[i] == 'Z')
                 s[i] = 'A';
             else
                 s[i]++;
        }
        i++;
    }
}

Although, perhaps, not the best way to write the function, we can create rot13() by utilising rotone().

#include <unitstd.h>

void rotone(char *s)
{
    int        i;
    if (!s)
        return ;
    i = 0;
    while (s[i] != '\0')
    {
        (s[i] >= 'a' && s[i] <= 'z' || (s[i]  >= 'A' && s[i] <= 'Z'))
        {
             if (s[i] == 'z')
                 s[i] = 'a';
             else if (s[i] == 'Z')
                 s[i] = 'A';
             else
                 s[i]++;
        }
        i++;
    }
}

void rot13(char *s)
{
    int        rotations;
    
    if (!s)
       return ;
    rotations = 0;
    while (rotations < 13)
    {
        rotone(s);
        rotations++;
    }

}

Of course, we could write a self-contained rot13() function,but to do that we need to introduce modulo arithmetic, which may prove hard while one is experiencing exam stress.

⚠️ **GitHub.com Fallback** ⚠️