fork download
  1. #include <stdio.h>
  2.  
  3. void UIntToHexStr (unsigned int uiValue, char pcStr[]){
  4.  
  5. unsigned char ucCharCounter;
  6.  
  7. pcStr[0]='0';
  8. pcStr[1]='x';
  9.  
  10. for(ucCharCounter=5; ucCharCounter!=1; ucCharCounter--){
  11. if((uiValue & 0x000F) < 10){
  12. pcStr[ucCharCounter]=(uiValue & 0x000F)+'0';
  13. }
  14. else{
  15. pcStr[ucCharCounter]=(uiValue & 0x000F) - 10 + 'A';
  16. }
  17. uiValue=uiValue>>4;
  18. }
  19.  
  20. pcStr[6]=NULL;
  21.  
  22. }
  23.  
  24.  
  25.  
  26. enum Result {OK,ERROR};
  27. enum Result eHexStringToUInt(char pcStr[],unsigned int *puiValue){
  28.  
  29. unsigned char ucCharCounter;
  30.  
  31. if(pcStr[0]!='0' || pcStr[1]!='x' || pcStr[0]!=NULL){
  32. return ERROR;
  33. }
  34.  
  35.  
  36. for(ucCharCounter=2; pcStr[ucCharCounter]!=NULL; ucCharCounter++){
  37.  
  38.  
  39. if(ucCharCounter>5){
  40. return ERROR;
  41. }
  42.  
  43. if(pcStr[ucCharCounter]>='A') {
  44. *puiValue=(*puiValue<<4) + (pcStr[ucCharCounter] - 'A' + 10);
  45. }
  46.  
  47. else{
  48. *puiValue=(*puiValue<<4) + (pcStr[ucCharCounter] - '0');
  49. }
  50.  
  51.  
  52. }
  53. return OK;
  54. }
  55.  
  56.  
  57.  
  58.  
  59. void AppendUIntToString(unsigned int uiValue, char pcDestinationStr[]){
  60.  
  61. unsigned char ucCharCounter;
  62.  
  63. for(ucCharCounter=0; pcDestinationStr[ucCharCounter]!=NULL; ucCharCounter++){}
  64. UIntToHexStr(uiValue, pcDestinationStr+ucCharCounter);
  65. }
  66.  
  67. int main(){
  68. unsigned int uiValue = 100;
  69. unsigned char pcStr[20]="";
  70. uIntToHexStr(uiValue, pcStr);
  71. int i;
  72. for(i=0;i<6;i++){
  73. printf("%c", pcStr[i]);}
  74.  
  75. unsigned int elo;
  76. unsigned int *wsknaelo;
  77. wsknaelo = &elo;
  78. eHexStringToUInt(pcStr,&wsknaelo);
  79.  
  80. printf("\ntu jest zamienona liczba %d", wsknaelo);
  81. return 0;
  82. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'UIntToHexStr':
prog.c:20:11: warning: assignment makes integer from pointer without a cast
   pcStr[6]=NULL;
           ^
prog.c: In function 'eHexStringToUInt':
prog.c:31:48: warning: comparison between pointer and integer
   if(pcStr[0]!='0' || pcStr[1]!='x' || pcStr[0]!=NULL){
                                                ^
prog.c:36:44: warning: comparison between pointer and integer
   for(ucCharCounter=2; pcStr[ucCharCounter]!=NULL; ucCharCounter++){
                                            ^
prog.c: In function 'AppendUIntToString':
prog.c:63:55: warning: comparison between pointer and integer
   for(ucCharCounter=0; pcDestinationStr[ucCharCounter]!=NULL; ucCharCounter++){}
                                                       ^
prog.c: In function 'main':
prog.c:70:2: warning: implicit declaration of function 'uIntToHexStr' [-Wimplicit-function-declaration]
  uIntToHexStr(uiValue, pcStr);
  ^
prog.c:78:19: warning: pointer targets in passing argument 1 of 'eHexStringToUInt' differ in signedness [-Wpointer-sign]
  eHexStringToUInt(pcStr,&wsknaelo);
                   ^
prog.c:27:13: note: expected 'char *' but argument is of type 'unsigned char *'
 enum Result eHexStringToUInt(char pcStr[],unsigned int *puiValue){
             ^
prog.c:78:25: warning: passing argument 2 of 'eHexStringToUInt' from incompatible pointer type
  eHexStringToUInt(pcStr,&wsknaelo);
                         ^
prog.c:27:13: note: expected 'unsigned int *' but argument is of type 'unsigned int **'
 enum Result eHexStringToUInt(char pcStr[],unsigned int *puiValue){
             ^
prog.c:80:2: warning: format '%d' expects argument of type 'int', but argument 2 has type 'unsigned int *' [-Wformat=]
  printf("\ntu jest zamienona liczba %d", wsknaelo);
  ^
/home/Mw2NqS/ccIGZ72G.o: In function `main':
prog.c:(.text.startup+0x40): undefined reference to `uIntToHexStr'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty