Advertisement
KitSaels

Return místo break ve switch

Sep 16th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. int hex_to_int(unsigned char input);
  8.  
  9. int main() {
  10.     char hex_input[6]; // tyto tri radky jsem vygooglil :-D
  11.     puts("Zadejte HTML kod barvy (bez hashtagu): ");
  12.     fgets(hex_input, 6, stdin);
  13.  
  14.     int out[6];
  15.  
  16.     out[0] = hex_to_int(hex_input[0]); // tady jsem mel for cyklus, ale kdyz to nefungovalo, zkusil jsem to rucne
  17.     cout << out[0] << endl;
  18.     cout << hex_input[0] << endl; // tady to pokazde vypise -1
  19.  
  20.     return 0;
  21. }
  22.  
  23. int hex_to_int(unsigned char input) {
  24.  
  25. switch(input) {
  26. case '0': return 0;
  27. case '1': return 1;
  28. case '2': return 2;
  29. case '3': return 3;
  30. case '4': return 4;
  31. case '5': return 5;
  32. case '6': return 6;
  33. case '7': return 7;
  34. case '8': return 8;
  35. case '9': return 9;
  36. case 'a': return 10;
  37. case 'A': return 10;
  38. case 'b': return 11;
  39. case 'B': return 11;
  40. case 'c': return 12;
  41. case 'C': return 12;
  42. case 'd': return 13;
  43. case 'D': return 13;
  44. case 'e': return 14;
  45. case 'E': return 15;
  46. case 'f': return 16;
  47. case 'F': return 16;
  48. default: return -1;
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement