Thursday, December 8, 2022

Downloading C on Windows

How to Download C on Windows



If you would like a video tutorial walking you step-by-step through how to download C on Windows, follow this link!

https://arizona.zoom.us/rec/share/sGm-awvyhJKseLMeqShXYtpqGBeptCR049OhoW8030tO2_op6oZJDoBEMBdFKWM-.gN73LpbIQC8Um1RF?startTime=1670620067000

Installing C/C++ on Your Computer

1. Open Visual Studio Code on your laptop or computer.

2. Click the icon, Extensions, on the left side of the screen. Then search C/C++ in the search bar.


3. Select Install. The installation should only take up to one minute to complete.

4. Next select File, then the "New Text File" button. Then select Save, and title your file with an appropriate label, and add ".c" at the end. This allows your file to be saved as a C/C++ file. This is a crucial step because otherwise the software will not be able to be accessed if the extension is not added to the file.




Installing Extensions and Compiler for C/C++

1. After installing the C/C++ extension, you may have noticed that there was a pop-up box, asking if you would like to install the recommended extensions for C/C++. This should pop up in the bottom right corner of the screen. Click Install

2. Next, it is time to install the compiler for C that is needed in order to run and execute the code. This tutorial will cover the installation for Windows only. For a MacBook, please find resources elsewhere, such as https://www.cs.auckland.ac.nz/~paul/C/Mac/xcode/. 

3. Follow this link to begin the installation of the compiler for Windows: https://sourceforge.net/projects/mingw.


4. After opening the page, click Download on the screen. This will begin downloading the MinGW GCC compiler.


5. Once it has finished downloading, select MinGW from your downloads and select Run. Another box should appear, and the select Install. Then select Continue. Then you will select Continue again. Then it should show a list of MinGW Installation packages.


6. Once you have reached this screen, select the boxes for both "mingw32-base" and "mingw32-gcc-g++". After you select these, you will confirm the button "Mark for Installation" for both boxes.


7. Next, click the Installation tab once more and select Apply Changes.
8. Next the box will ask if it is okay to proceed, in which you will answer Apply. This will begin more downloading.

9. After the downloading of the packages, wait until it the box says, "All changes were applied successfully; you may now close this dialogue", then select Close.

10. We have downloaded and installed the MinGW compiler, and now it is time to set the environment path. First go to your file directory and find the MinGW folder that has now been created.

11. Double click on this folder and then select bin in the folder.

12. Then copy and paste the directory path from the steps above. The path will be labeled C:\MinGW\bin. Then go to This PC, right click on This PC, then select Properties

13. Then search Advanced system settings in the search bar, and then select Environment Variables

14. Select Path under System Variables and then select Edit.

15. A popup window should show and first click New, then paste the C:\MinGW\bin in the box, and then click OK

16. To check that MinGW was fully installed, go the Command Prompt window and type ' gcc --version ', then press Enter.



Creating a Folder for C

1. First go to your file directory and select New Folder. To be concise, we recommend titling the folder C Program

2. Next go back to Visual Studio Code and select Add Folder.

3. After clicking Add Folder, select your C Program folder in the dialog box. Then select Add

4. The folder C Program should now be seen in Visual Studio. 



To ensure that the installation and downloading process was successful, let's perform a basic code! 

In this first tutorial we will write a basic function to print "Hello World!". To display the message, we will utilize the function printf.


Example 1

Input:
#include <stdio.h> 
int main()
{
printf("Hello World!") ; // printf displays what is in double quotes
return 0 ;
}

Ouput:

Hello World! 

** #include <stdio.h> communicates to the compiler to include the stdio.h file in the program. This is standard for both functions scanf() and printf(). 

** int main() is the function name and int is known as the return type of the function. The 0 return value represents that the program was successful, while the return value of 1 represents that the program was unsuccessful. 





Side Note

One of the best ways to produce organized and clean code is to comment on each of your lines of code. To comment in C/C++, the user must type // before the comment, and the text should turn green






No comments:

Post a Comment