Program to Print several types of alphabets

#include "stdio.h"
#include "ctype.h"
#include "getopt.h"
#define PACKAGE "alphabet"
#define VERSION "0.0.5"
/*
// `0' westeren, `1' phonetic, `2' greek `3' hebrew
// `4' phoenician `5' arab
*/
static int type = 0;
/* all output upper case */
static int upper = 0;
/* recursive, output until killed */
static int recur = 0;

/* phonetic alphabet */
const char *palpha[]= { "alpha", "bravo", "charlie", "delta",
"echo", "foxtrot", "golf", "hotel",
"india", "juliet", "kilo", "lima",
"mike", "november", "oscar", "papa",
"quebec", "romeo", "sierra", "tango",
"uniform", "victor", "whisky", "x-ray",
"yankee", "zulu" };

/* lower case greek alphabet */
const char *galpha[]= { "alpha", "beta", "gamma", "delta",
"epsilon", "zeta", "eta", "theta",
"iota", "kappa", "lambda", "mu",
"nu", "xi", "omicron", "pi",
"rho", "sigma", "tau", "upsilon",
"phi", "chi", "psi", "omega" };

/* lower case hebrew alphabet */
const char *halpha[]= { "tet", "chet", "zayin", "vav",
"he", "dalet", "gimel", "bet",
"alef", "samech", "nun", "nun",
"mem", "mem", "lamed", "khaf",
"kaf", "yod", "tav", "shin",
"resh", "qof", "tzade", "tzade",
"fe", "pe", "ayin" };

/* lower case phoenician alphabet */
const char *nalpha[]= { "aleph", "beth", "gimel", "daleth",
"he", "waw", "heth", "yodh",
"kaph", "lamedh", "mem", "nun",
"ayin", "pe", "qoph", "resh",
"sin", "taw", "waw", "samekh",
"zayin" };

/* lower case arab alphabet */
const char *aalpha[]= { "xaa", "haa", "jiim", "th!aa",
"taa", "baa", "alif", "saad",
"shiin", "siin", "zaay", "raa",
"thaal", "daal", "qaaf", "faa",
"ghayn", "ayn", "th:aa", "taa",
"daad", "yaa", "waaw", "haa",
"nuun", "miim", "laam", "kaaf" };

/* status epilepticus, and die with `exval' */
void print_help(int exval);
/* print the specified alphabet */
void print_alphabet(void);

int main(int argc, char *argv[]) {
int opt = 0;

/* option parser */
while((opt = getopt(argc, argv, "hvpgwiaru")) != -1) {
switch(opt) {
case 'h': /* print help and exit */
print_help(0);
case 'v': /* print version and exit */
exit(0);
case 'p': /* print the phonetic alphabet */
type = 1;
break;
case 'g': /* print the lower case greek alphabet */
type = 2;
break;
case 'w': /* print the lower case hebrew alphabet */
type = 3;
break;
case 'i': /* print the lower case phoenician alphabet */
type = 4;
break;
case 'a': /* print the lower case arab alphabet */
type = 5;
break;
case 'r': /* print the alphabet repeatedly until killed */
recur = 1;
break;
case 'u': /* print all output upper case */
upper = 1;
break;
case '?': /* unkown option */
fprintf(stderr, "%s: Error - no such option `%c'\n\n", PACKAGE, optopt);
print_help(1);
break;
} /* switch */
} /* while */

/* prints the selected alphabet */
print_alphabet();

return 0;
}

/* prints the selected alphabet */
void print_alphabet(void) {
const char *ptr = NULL;
int i = 0;

/* western alphabet */
if(type == 0) {
if(upper == 0)
for(i = 97; i <= 122; i++)
printf("%c\n", i);
else
for(i = 65; i <= 90; i++)
printf("%c\n", i);
/* phonetic alphabet */
} else if(type == 1) {
if(upper == 0) {
for(i = 0; i <>
printf("%s\n", palpha[i]);
} else {
for(i = 0; i <>
ptr = palpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
/* greek alphabet */
} else if(type == 2) {
if(upper == 0) {
for(i = 0; i <>
printf("%s\n", galpha[i]);
} else {
for(i = 0; i <>
ptr = galpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
} else if(type == 3) {
if(upper == 0) {
for(i = 0; i <>
printf("%s\n", halpha[i]);
} else {
for(i = 0; i <>
ptr = halpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
} else if(type == 4) {
if(upper == 0) {
for(i = 0; i <>
printf("%s\n", nalpha[i]);
} else {
for(i = 0; i <>
ptr = nalpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
} else if(type == 5) {
if(upper == 0) {
for(i = 0; i <>
printf("%s\n", aalpha[i]);
} else {
for(i = 0; i <>
ptr = aalpha[i];
while(*ptr)
printf("%c", toupper(*ptr++));
printf("\n");
} /* for */
} /* else */
} /* else if */

if(recur == 1)
print_alphabet();
else
return;
}

/* status epilepticus, and die with `exval' */
void print_help(int exval) {
printf("%s,%s prints different alphabets\n", PACKAGE, VERSION);
printf("Usage: %s [-h] [-v] [-p] [-g] [-w] [-i] [-a] [-r] [-u]\n\n", PACKAGE);

printf(" Startup:\n");
printf(" -h print this help and exit\n");
printf(" -v print version and exit\n\n");

printf(" Alphabet:\n");
printf(" -p print the phonetic alphabet\n");
printf(" -g print the greek alphabet\n");
printf(" -w print the hebrew alphabet\n");
printf(" -i print the phoenician alphabet\n");
printf(" -a print the arab alphabet\n\n");

printf(" Output:\n");
printf(" -r print the alphabet repeatedly until killed\n");
printf(" -u print all output in upper case\n\n");

printf(" Per default the Westeren alphabet is printed\n");
exit(exval);
}

Related Links :

1 comment:


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!