fork download
  1. #include <stdio.h> /* printf */
  2. #include <stdlib.h> /* strtol */
  3. #include <string.h>
  4.  
  5. int main ()
  6. {
  7. //char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
  8. //char szNumbers[] = "94 c7 94 d2 94 c6 94 9e";
  9. unsigned char szNumbers[] = "94c794d294c69498";
  10. //char szNumbers[] = "94c7";
  11. //char szNumbers1[2];
  12.  
  13. // Get first 4 characters of szNumbers
  14. /*char group1[5]; // note 6, not 5, there's one there for the null terminator
  15.   strncpy(group1, szNumbers, 4);
  16.   group1[4] = '\0'; // place the null terminator
  17.   printf("group1: %s\n", group1);
  18.  
  19.   // Get next 4 characters of szNumbers
  20.   char group2[5]; // note 6, not 5, there's one there for the null terminator
  21.   strncpy(group2, szNumbers+4, 4);
  22.   group2[4] = '\0'; // place the null terminator
  23.   printf("group2: %s\n", group2);
  24.  
  25.   // Get next 4 characters of szNumbers
  26.   char group3[5]; // note 6, not 5, there's one there for the null terminator
  27.   strncpy(group3, szNumbers+8, 4);
  28.   group3[4] = '\0'; // place the null terminator
  29.   printf("group3: %s\n", group3);
  30.  
  31.   // Get next 4 characters of szNumbers
  32.   char group4[5]; // note 6, not 5, there's one there for the null terminator
  33.   strncpy(group4, szNumbers+12, 4);
  34.   group4[4] = '\0'; // place the null terminator
  35.   printf("group4: %s\n", group4);*/
  36.  
  37. char v1[5], v2[5], v3[5], v4[5];
  38.  
  39. strncpy(v1, (char*)szNumbers, 4);
  40. strncpy(v2, (char*)szNumbers+4, 4);
  41. strncpy(v3, (char*)szNumbers+8, 4);
  42. strncpy(v4, (char*)szNumbers+12, 4);
  43.  
  44. // Place the null terminator for all groups
  45. v1[4] = '\0';
  46. v2[4] = '\0';
  47. v3[4] = '\0';
  48. v4[4] = '\0';
  49.  
  50. // Convert the hex value of each voltage to its base 10 equivalent
  51. long int li1 = strtol (v1, NULL, 16);
  52. long int li2 = strtol (v2, NULL, 16);
  53. long int li3 = strtol (v3, NULL, 16);
  54. long int li4 = strtol (v4, NULL, 16);
  55. printf ("The decimal equivalents are: %ld %ld %ld %ld \n", li1, li2, li3, li4);
  56.  
  57. //char * pEnd;
  58. /*long int li1 = strtol (szNumbers1, NULL, 16);
  59.   printf ("The decimal equivalents are: %ld\n", li1);*/
  60. //printf ("pEnd: %s\n", pEnd);
  61.  
  62. //char szNumbers[] = "94 c7";
  63. /*char * pEnd;
  64.   long int li1, li2;
  65.   li1 = strtol (szNumbers,&pEnd,10);
  66.   printf ("endptr: %s\n", pEnd);
  67.  
  68.   li2 = strtol (pEnd, &pEnd , 10);
  69.   printf ("The decimal equivalents are: %ld %ld ", li1, li2);*/
  70.  
  71. /*char * pEnd;
  72.   long int li1, li2, li3, li4;
  73.   li1 = strtol (szNumbers,&pEnd,10);
  74.   printf ("pEnd: %s\n", pEnd);
  75.   li2 = strtol (pEnd,&pEnd, 16);
  76.   li3 = strtol (pEnd,&pEnd, 16);
  77.   li4 = strtol (pEnd,&pEnd, 16);
  78.   printf ("The decimal equivalents are: %ld, %ld, %ld and %ld.\n", li1, li2, li3, li4);
  79.   return 0;*/
  80.  
  81.  
  82. /*while(strlen(pEnd) > 0){
  83.   long int liN;
  84.   liN = strtol(pEnd,&pEnd,10);
  85.   printf("%ld ", liN);
  86.   }*/
  87.  
  88. return 0;
  89. }
  90.  
Success #stdin #stdout 0s 4276KB
stdin
Standard input is empty
stdout
The decimal equivalents are: 38087 38098 38086 38040