fork download
  1. #include <stdio.h>
  2.  
  3. void inputChar(char *str)
  4. {
  5. printf("input array char <100: ");
  6. scanf("%s", str);
  7. }
  8. void revers(char *A)
  9. {
  10. int j;
  11. for (j = 0; A[j] != '\0'; j++);
  12. j--;
  13. for (int i = 0; i <j; i++, j--)
  14. {
  15. char temp = A[i];
  16. A[i] = A[j];
  17. A[j] = temp;
  18. }
  19. }
  20. int charToDecInt(char *A)
  21. {
  22. int summ = 0;
  23. for (int i = 0; A[i] != '\0'; i++)
  24. {
  25. if ('0' <= A[i] && A[i] <= '9')
  26. {
  27. summ *= 10;
  28. summ += A[i] - '0';
  29. }
  30. else
  31. {
  32. summ += A[i]-'A'+10;
  33. }
  34.  
  35. }
  36. return summ;
  37. }
  38. void decIntTohexString(int a, char *A)
  39. {
  40. int j = 0;
  41. while (a != 0)
  42. {
  43. int r = a % 16;
  44. if (r >= 1 && r <= 9)
  45. {
  46. r += '0';
  47. }
  48. else
  49. {
  50. r += 'A'- 10;
  51. }
  52. A[j++] = r+A[j];
  53. a /= 16;
  54. }
  55. A[j] = '\0';
  56. revers(A);
  57. }
  58. void display()
  59. {
  60. const int N = 100;
  61. char A[100] = {};
  62. char B[100] = {};
  63. inputChar(A);
  64. int a = charToDecInt(A);
  65. decIntTohexString(a, B);
  66. printf("hexChar = %s\n", B);
  67. }
  68. int main()
  69. {
  70. display();
  71. return 0;
  72. }
Success #stdin #stdout 0s 9432KB
stdin
444444asdf
stdout
input array char <100: hexChar = 6C8DE