Computer Programming for Engineers Introduction to Programming in C Language on Visual C Platform Intro. Comp. Prog. C-Language1
Getting Started on on Visual C The platform is Microsoft Visual C Express Edition Go to All Programs Visual C Express Edition Microsoft Visual C Express Edition Make sure the Start Page “Show empty environment” and this is how to do it Intro. Comp. Prog. C-Language2
3 Open Visual C Start Page
Start Page “Show empty environment” Go to Tools—Options—Start Up And select Show empty environment as shown in the Fig. below Intro. Comp. Prog. C-Language4 Select File—Exit. And reopen the Visual Studio C
Intro. Comp. Prog. C-Language5 Set your environment
Fig. Main window Visual C++ without Start Page Intro. Comp. Prog. C-Language6
Write your first (second,…) program Intro. Comp. Prog. C-Language7
First Program on Visual C++ Express 1. Select File New Project. A window will pop up as shown in the Fig Intro. Comp. Prog. C-Language8 Fig. New Project
2. Go to Project types -> General. 3. Select Empty Project. Type entaneer_cmu for the Project Name 4. Do not change the Location: and Solution Name at this point Intro. Comp. Prog. C-Language9 Fig. New Project
Fig. New Project window Intro. Comp. Prog. C-Language10
3. Go to Project Tab and Select Add New Item 4. Under Code: Create a new file called test.c Intro. Comp. Prog. C-Language11
Fig. Editor window for entering your code Intro. Comp. Prog. C-Language12
5. Enter the following codes in the editor window #include void main() { printf(" Computer Programming for Engineers!\n"); } Intro. Comp. Prog. C-Language13
Fig. Editor window showing your first program Intro. Comp. Prog. C-Language14
6. Save the file (under the name test.C) 7. Under Build, select Build Solution (Or press F7) to create an output file 8. If successful, the following message will appear in the output box Intro. Comp. Prog. C-Language15 ======== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Fig. Result on Building the solution in the output Tab Intro. Comp. Prog. C-Language16
Possible Errors : Example 1 You can make possible syntax errors in C programming. For example, type in stead of in the first line. Now Save and Build the solution (F7). A syntax error message should appear in the output dialog box Intro. Comp. Prog. C-Language17 #include void main() { printf(“ Computer Programming for Engineers!\n”); }
Fig. Syntax error in output tab for example Intro. Comp. Prog. C-Language18
More information on the errors Intro. Comp. Prog. C-Language19.\test.c(1) : fatal error C1083: Cannot open include file: 'studio.h': No such file or directory.\test.c(1) means the file “test.c”, and (1) means the error is found in Line-1 “Cannot open include file: 'studio.h': No such file or directory” means the library studio.h cannot be found. The correct library is stdio.h, which is needed for C-programming
Now Change printf to print without the “f” And re-build the solution Intro. Comp. Prog. C-Language20 #include void main() { print(“ Computer Programming for Engineers!\n”); } Possible Errors : Example 2
Fig. Syntax error in output tab for example Intro. Comp. Prog. C-Language21
Now correct your code, and build the solution Intro. Comp. Prog. C-Language22 Run your first program ======== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
8. Go to Debug, and run the program by selecting Start Without Debugging (or Ctrl-F5). The run results appear as shown in the Fig. below Intro. Comp. Prog. C-Language23 รูปที่ 13 command window showing the results
Intro. Comp. Prog. C-Language24 Run Result Press any key, and the command window box will disappear
10. After finishing with the project, you can leave the Visual C++ program. 11. To re-open the program. Go to File -> Open and select Project/Solution… and select Project1.sln, Intro. Comp. Prog. C-Language25
Open your solution Intro. Comp. Prog. C-Language26