259201 Computer Programming for Engineers Introduction to Programming in C Language on Visual C++...

26
Programming for Engineers Introduction to Programming in C Language on Visual C++ 2005 Platform 259201 Intro. Comp. Prog. C-Language 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

259201 Intro. Comp. Prog. C-Language 3

Open Visual C++ 2005 Start Page

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

259201 Intro. Comp. Prog. C-Language 5

Set your environment

Fig. Main window Visual C++ without Start Page

259201 Intro. Comp. Prog. C-Language 6

Write your first (second,…) program

259201 Intro. Comp. Prog. C-Language 7

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

Fig. New Project window

259201 Intro. Comp. Prog. C-Language 10

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

Fig. Editor window for entering your code

259201 Intro. Comp. Prog. C-Language 12

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

Fig. Editor window showing your first program

259201 Intro. Comp. Prog. C-Language 14

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 ==========

Fig. Result on Building the solution in the output Tab

259201 Intro. Comp. Prog. C-Language 16

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”);}

Fig. Syntax error in output tab for example 1.

259201 Intro. Comp. Prog. C-Language 18

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

Fig. Syntax error in output tab for example 2.

259201 Intro. Comp. Prog. C-Language 21

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

Open your solution

259201 Intro. Comp. Prog. C-Language 26