[ create a new paste ] login | about

Link: http://codepad.org/5u5uO5ZR    [ raw code | output | fork | 4 comments ]

kinopiko - C, pasted on Oct 25:
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int getpos (char c)
{
    int pos;
    const char * alphabet = "abcdefghijklmnopqrstuvwxyz";
    const char * found;

    c = tolower (c);
    found = strchr (alphabet, c);
    pos = found - alphabet;
    if (!found)
        pos = 0;
    else if (pos == 26)
        pos = 0;
    else
        pos++;
    return pos;
}

int main ()
{
    char tests[] = {'A', '%', 'a', 'z', 'M', 0};
    char * c;
    for (c = tests; *c; c++) {
        printf ("%d\n", *c - 'a' + 1);
        printf ("%d\n", getpos (*c));
    }
    return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
-31
1
-59
0
1
1
26
26
-19
13


Create a new paste based on this one


Comments:
posted by jkjkjll on Jun 12
write a program to display the alphabets of english language
reply
posted by jkjkjll on Jun 12
kljk;
reply
posted by jkjkjll on Jun 12
;kjj;;jk;
reply
posted by jkjkjll on Jun 12
j;;;jk;uo;ioh
reply