259201 Computer Programming for Engineers Introduction to Programming in C Language on Visual C++...
-
Upload
gervais-robertson -
Category
Documents
-
view
239 -
download
1
Transcript of 259201 Computer Programming for Engineers Introduction to Programming in C Language on Visual C++...
259201 Computer Programming for Engineers
Introduction to Programming
in C Language on
Visual C++ 2005 Platform
259201 Intro. Comp. Prog. C-Language 1
Getting Started on on Visual C++ 2005The platform is Microsoft Visual C++ 2005
Express Edition Go to All Programs Visual C++ 2005
Express Edition Microsoft Visual C++ 2005 Express Edition
Make sure the Start Page “Show empty environment” and this is how to do it.
259201 Intro. Comp. Prog. C-Language 2
Start Page “Show empty environment”Go to Tools—Options—Start UpAnd select Show empty environment as shown in the
Fig. below
259201 Intro. Comp. Prog. C-Language 4
• Select File—Exit. And reopen the Visual Studio C++ 2005
First Program on Visual C++ Express
1. Select File New Project. A window will pop up as shown in the Fig.
259201 Intro. Comp. Prog. C-Language 8
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
259201 Intro. Comp. Prog. C-Language 9
Fig. New Project
1 2
3
4 5
3. Go to Project Tab and Select Add New Item4. Under Code: Create a new file called test.c
259201 Intro. Comp. Prog. C-Language 11
5. Enter the following codes in the editor window
#include <stdio.h>void main(){
printf("259201 - Computer Programming for Engineers!\n");
}
259201 Intro. Comp. Prog. C-Language 13
6. Save the file (under the name test.C)7. Under Build, select Build Solution (Or
press F7 ) to create an output file8. If successful, the following message will
appear in the output box
259201 Intro. Comp. Prog. C-Language 15
======== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Possible Errors : Example 1You can make possible syntax errors in C programming. For example, type <studio.h> in stead of <stdio.h> in
the first line. Now Save and Build the solution (F7) . A syntax error
message should appear in the output dialog box.
259201 Intro. Comp. Prog. C-Language 17
#include <studio.h>void main(){ printf(“259201 - Computer Programming for Engineers!\n”);}
More information on the errors
259201 Intro. Comp. Prog. C-Language 19
.\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
259201 Intro. Comp. Prog. C-Language 20
#include <stdio.h> void main(){ print(“259201 - Computer Programming for Engineers!\n”);}
Possible Errors : Example 2
Now correct your code, and build the solution
259201 Intro. Comp. Prog. C-Language 22
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.
259201 Intro. Comp. Prog. C-Language 23
รู�ปที่�� 13 command window showing the results
259201 Intro. Comp. Prog. C-Language 24
Run ResultPress 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,
259201 Intro. Comp. Prog. C-Language 25