Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Team Competition
- Here is a fun game for our last session. Your team's job is to find out what a mystery program does.
- If a team thinks they have the answer, have one designated member leave their breakout room and explain to me what it does.
- If they get it correct, their team wins, I break all of the rooms and the winning team gets bragging rights. If not, I
- will send them back into their room to keep working with their team to figure out the program.
- RULES
- 1) All teams have 15 minutes. If no one gets it in that time, then I explain what the program does and no one gets bragging rights,
- that sounds like no fun :(
- 2) You must be able to explain to me in detail what the program does! Not just bits and pieces or a vague explanation.
- - You must also explain what the functions do. I can't have you just RUN the program and get off easy.
- 3) Each team has 2 attempts to explain the program to me. If they use all 2 and don't get it on either, they lose.
- - I won't pull any punches. If you're wrong I'm saying "Nah" and sending you back to the breakout room. No Hints.
- 4) I will send the pastebin with the mystery program right after debriefing on the game. Enter your breakout room as soon as you
- get the pastebin link.
- Problem #1
- This problem involves using argc and argv for input and output. Program the following:
- 1) Write your main function with parameters "int argc" and "char* argv[]".
- - This program should take a string as input AT THE COMMAND LINE when the program is started.
- 2) Print the words in the string in reverse order.
- - You will need to use argc and argv.
- Note: Recall that char* argv[] is an array of STRINGS. So each input string occupies
- a single slot in the array.
- SAMPLE OUTPUT:
- > ./main here are my words [This is the command line. NOT your program output.]
- words -------\
- my \
- are - [These lines are your output, from "words" to "./main"]
- here /
- ./main -------/
- Problem #2
- This problem involves using File pointers! Program the following:
- 1) Prompt the user for the name of a text file (example: input.txt)
- - Use fscanf() to put the user input in a string.
- 2) Check if the file exists. Print the result to the user.
- SAMPLE OUTPUT (If file exists) SAMPLE OUTPUT (If file doesn't exist)
- Enter your file: file.txt Enter in your file: file.txt
- File exists File doesn't exist
- Problem #3
- This problem involves creating arrays by explicitly allocating the memory using calloc(). Program the following:
- 1) Declare a pointer of type int and initialize it to NULL.
- 2) Prompt the user for the size of the array.
- - Doesn't matter the size as long as you don't put in a huge number (Cause you are gonna manually enter the numbers later).
- 3) Use calloc() and allocate the array based on the user input for the size.
- - Example code for how to do this provided below.
- 4) Fill the array with numbers supplied by the user. Do this one at a time.
- 5) Print the values to the screen to prove it worked.
- - Don't forget to use free() at the end.
- Example: Using calloc to get memory of x number of type int elements.
- (int*)calloc(x, sizeof(int));
- SAMPLE OUTPUT
- Enter the number of items: 5
- Enter values to put in the array:
- 1
- 2
- 3
- 4
- 5
- Here are the values in the array:
- 1 2 3 4 5
- BONUS PROBLEM
- This problem is similar to problem 3, but using malloc() instead. Program the following:
- 1) Declare an uninitialized string using pointer notation.
- -Example: char *str;
- 2) Use malloc() to allocate an array of size 15.
- -Example shown below.
- 3) Initialize the string to a word or phrase under 15 characters.
- 4) Print the string, and the address its stored in.
- -Use the "%u" specifier for printing the address.
- 5) Use realloc() to up the size of the array to 30.
- 6) Repeat steps 3 and 4 with a larger string.
- Example: Allocate a string of size 40.
- (char*)malloc(40);
- SAMPLE OUTPUT
- String = Hereismystring; Address = 6709856
- String = Hereismystring, its larger now; Address = 6710928
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement