1 /* Reads a number from stdin and prints it 2 in hexadecimal base on stout; */ 3 4 #include <stdio.h> 5 #include <stdlib.h> 6 7 #define MAX_LEN 100 8 9 int main ( void ) { 10 11 char buffer[MAX_LEN]; 12 int num; 13 char num2[MAX_LEN]; 14 15 if(fgets(buffer, MAX_LEN, stdin) == NULL) 16 return 1; 17 18 num = atoi(buffer); 19 20 /* Converts num to hexadecimal and stores it 21 on num2 str; */ 22 sprintf(num2, "%x\n", num); 23 24 /* prints the string with the octal number; */ 25 printf("%s", num2); 26 return 0; 27 }