Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
10
Добавлен:
26.05.2014
Размер:
1.29 Кб
Скачать
  #ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
char  ch[4];
int base;
char  val[20];
int	c[255];
char	m[6]={'A','B','C','D','E','F'};
int i,j,value;
again:
system("setterm -fore green -s");
system("tput clear");
system("echo Hellow");
system("whoami");
printf("Input base of value:");
scanf("%d",&base);
printf("Input a value:");
scanf("%s",&val);
i=0;
while (val[i]!=NULL)
i++;
printf("You entered a %d digit\n",i);
printf("Translating your digit to 10 base value\n");
value=strtol(val,NULL,base);
printf("In a 10 base your value is %i\n",value);
base_again:
printf("Please enter the base to translate for:");
scanf("%i",&base);
if (base>16|base<2)
{printf("Must be more than 2 and less than 16 !...\n");
goto base_again;}

i=0;
while (value>0)
{
c[i]=value%base;
if (c[i]>9)
{
c[i]=m[c[i]-10];
}
value=(int)value/base;
i=i++;
}
printf("Result is:");
for (j=i-1;j>=0;j--)
{
if (j%4==3)
printf(" ");
if (c[j]>9)
printf("%c",c[j]);
else
printf("%i",c[j]);
}
printf("\nWould you like to try again? [yes|no] ");
scanf("%s",&ch);
if (ch[0]=='n') goto final;
else goto again;
final:
return EXIT_SUCCESS;
}


Соседние файлы в папке er