Project 2.1 C Intro and Variables


Intro to Programming Languages.

[ ← Module List ]

Greetings Coders!
Welcome aboard the C programming adventure! 🚀 Prepare to dive deep into the essence of computing as you craft, assess, and master the art of C programming.
In this captivating challenge set, you'll:
  • Create a minimal C program
  • Declare and define variables using primitive data types
  • List the primitive data types
  • Generate output to standard output using (printf)
  • Gather input using standard input (getchar, scanf)
  • Use branching statements to control program flow
  • Use loops to repeat portions of code
  • Loop flow control with break and continue
  • Access program arguments passed in via the command line.
  • Declare global variables
  • Declare local variables
  • Define functions
  • Pass arguments into a function using function parameters
  • Change a value in a function and return it

  • Are you ready to embark on this exhilarating journey? Let's get coding! 🛠🔍🖥


    Challenges

    Welcome to C! Your C program must do the following to pass the system_tests (they are available in that directory) You will need to create a program that prints out: May the force be with you. The program should use printf to write to standard output, which requires #include It will exit with a return code of 0 (by using return 0 from main) The program must be successfully compiled in the terminal Access the terminal from the VSCode by right clicking in the File Explorer Side Bar and clicking "Open in Integrated Terminal" or you can use the shortcut ctrl-~ (the tilde button, near the esc on left side of keyboard) cd to ~/cse240/21-proj-c-intro-vars/01 Use gcc main.c -g -o main.bin Check that the program works by using ./main.bin

    📋 Requirements available in VS Code!

    Click the "Requirements" button in the status bar (bottom right of VS Code) or use the keyboard shortcut Ctrl+Shift+Q to view the full assignment requirements.

    Requirements button location

    Connect with SSH

    Link your SSH key, then connect with: ssh [email protected]

    Objective In this challenge, you will write a C program that receives command line arguments. Command Line Arguments To receive command line arguments it must have the appropriate main function, like this. int main(int argc, char *argv[] ) Using this format for main, you will have access to argc : which holds the number of arguments passed into the program argv : which holds an array of the arguments Example, if we ran a program with ./main.bin "arg1" Then, argc = 2 argv[0] = "./main.bin" argv[1] = "arg1" To solve this challenge, you must fill in the missing code in the main.c file (look for CODE: ) Once your program is written, run /challenge/tester to get the flag.

    📋 Requirements available in VS Code!

    Click the "Requirements" button in the status bar (bottom right of VS Code) or use the keyboard shortcut Ctrl+Shift+Q to view the full assignment requirements.

    Requirements button location

    Connect with SSH

    Link your SSH key, then connect with: ssh [email protected]

    Objective In this challenge, you will write a C program that receives numerical input using scanf and a test case for it. scanf() Info To read in a number using scanf, we use scanf("%d", &myintvar); NOTE: any primitive data type (char, int, float, etc.) used with scanf must be preceeded by a & otherwise it will not receive the entered value Steps to Complete Modify the supplied main.c by inserting the code whereever there's a CODE: in a comment or a string. Modify ~/cse240/21-proj-c-intro-vars/02/user_tests/utest3.1.json with some input and output that will determine if the running total is working. HINT: you can run both modelGood.bin and modelBad3.1.bin to see what should be detected

    📋 Requirements available in VS Code!

    Click the "Requirements" button in the status bar (bottom right of VS Code) or use the keyboard shortcut Ctrl+Shift+Q to view the full assignment requirements.

    Requirements button location

    Connect with SSH

    Link your SSH key, then connect with: ssh [email protected]

    Objective The next challenge uses getchar() to get user input and make selections from a menu. getchar() Info The getchar() function gets a single character from standard input. It returns an unsigned char (or in most instances basically a char) containing the entered value. NOTE: If the user input is terminated with an enter, the enter gets caught in the buffer. So, it is necessary to follow up the getchar() with another to clear the enter out of the buffer. Steps to Complete Modify the provided code according to the CODE: comments Write a user test 4.1 that tests the insert function call Write a user test 4.2 that tests for "Error entry not in the list" when an invalid choice is made Run /challenge/tester and get your flag. HINT: If the code relies on a switch statement, then for 0 it will need separate functionality to exit the loop, an if (ch=='0') after the switch will work. This is necessary because a break from inside the switch is absorbed by it and does not exit the loop.

    📋 Requirements available in VS Code!

    Click the "Requirements" button in the status bar (bottom right of VS Code) or use the keyboard shortcut Ctrl+Shift+Q to view the full assignment requirements.

    Requirements button location

    Connect with SSH

    Link your SSH key, then connect with: ssh [email protected]

    Objective In this challenge, you will create your own menu, functions, and variables. The program will print a menu that allows for adding to and subtracting from a global variable called current_value. Steps to Complete Modify the provided code according to the CODE: comments Compile the program Test that your program is working as expected Run /challenge/tester and get your flag. HINT: The variable name and function names will be verified during the tests. Please be precise.

    📋 Requirements available in VS Code!

    Click the "Requirements" button in the status bar (bottom right of VS Code) or use the keyboard shortcut Ctrl+Shift+Q to view the full assignment requirements.

    Requirements button location

    Connect with SSH

    Link your SSH key, then connect with: ssh [email protected]

    Objective Your task is to review, identify, and fix errors in the provided C code. Program Should Complete the Following Allow the user to enter the first number Allow the user to enter the second number Print out the sum of the two values.

    📋 Requirements available in VS Code!

    Click the "Requirements" button in the status bar (bottom right of VS Code) or use the keyboard shortcut Ctrl+Shift+Q to view the full assignment requirements.

    Requirements button location

    Connect with SSH

    Link your SSH key, then connect with: ssh [email protected]

    30-Day Scoreboard:

    This scoreboard reflects solves for challenges in this module after the module launched in this dojo.

    Rank Hacker Badges Score