I got a question one of my friends asked me to make a program that you type in the number 1-27 on the command line, and get the corresponding letter for it. Like if you enter 1 as the arguement you would get an A as an output, and if you type in 2, and get a B for the output and so on.

I got a question one of my friends asked me to make a program that you type in the number 1-27 on the command line, and get the corresponding letter for it. Like if you enter 1 as the arguement you would get an A as an output, and if you type in 2, and get a B for the output and so on.

It would help if you supplied your code to see where you are having problems.

I don't have any code for it, he was just wanted me to do some code for him, sense I am out fo work for a couple of weeks, with a broke leg, and have nothing to do, but I still do work for job at home, and don't have the time to do this for him.

I think this code will help you out

# include<stdio.h>
# include<conio.h>
char change(int); /* Function prototype */
void main()
{   int num;
    clrscr();
    printf("Enter any number : ");
    scanf("%d",&num); /* getting the no from user */
    printf("%c",change(num));
    getch();

}

char change(int n)
{   char k;
    k = (char)n;
    k = k+64;
    return k;
}

for command line arguement

# include<stdio.h>
# include<conio.h>
# include<stdlib.h>
char change(int); /* Function prototype */
int atoi(char);
void main(int count,char *argv[])
{    if(count != 2)
      {  puts("INVALID COMMAND");
          exit(0);
      }
      int num;
     num = atoi(argv[1]);
      printf("%c",change(num));
     getch();
}

char change(int n)
{   char k;
     k = (char)n;
     k = k+64;
    return k;
}
int atoi(char c)
{  return c - '0';
}

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.