Docsity

Getting Started with C Programming in Visual Studio for EE114 Students - Prof. Lan Xiang, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
1
1
EE114:
Programming Concepts for Engineers
Lecture 1
2
Introduction
nWhy C?
nC is a general purpose programming language
nEfficient and popular
nOther programming languages: C++, Java, Matlab, etc
nSoftware
nMicrosoft Visual Studio C++ 6.0 (included in the book)
nMicrosoft Visual Studio .net (available at computer labs:
SE322, CS21, CS21A, Math & Science Center etc)
nTextbook
nC How to Program, Prentice-Hall, by Deitels
nWe only cover Chapter 1 to Chapter 13
nExcellent book for you to self-study C++ and Java
3
nCreate
nType in the source code of the program (.c, .h files)
Visual Studio C++ .net
nCompile
nConvert the source code into machine code
(generate .exe file)
nRun
nTell the computer to run your program (run the .exe file)
nSimple programming concepts
4
Open VS C++ .net
pf3
pf4
pf5

Partial preview of the text

Download Getting Started with C Programming in Visual Studio for EE114 Students - Prof. Lan Xiang and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

1

EE114:

Programming Concepts for Engineers

Lecture 1

2

Introduction

n Why C? n C is a general purpose programming language n Efficient and popular n Other programming languages: C++, Java, Matlab, etc n Software n Microsoft Visual Studio C++ 6.0 (included in the book) n Microsoft Visual Studio .net (available at computer labs: SE322, CS21, CS21A, Math & Science Center etc) n Textbook n C How to Program, Prentice-Hall, by Deitels n We only cover Chapter 1 to Chapter 13 n Excellent book for you to self-study C++ and Java

3

n Create n Type in the source code of the program (.c, .h files)

Visual Studio C++ .net

n Compile n Convert the source code into machine code (generate .exe file)

n Run n Tell the computer to run your program (run the .exe file)

n Simple programming concepts

4

Open VS C++ .net

5

Create a Project

Click the menu item File | New | Project....

A dialog box is displayed.

  • In the left pane expand the selection named Visual C++ Projects
  • and then select Win32.
  • In the right pane, select Win32 Console Project.
  • In the Name: text box type hello.
  • In the Location: text box, click on the button to browse to the folder you created in the previous step.

6

click OK to continue

7

Click Application Settings on the left side of the window and then place a check in the box marked Empty project. The screen should look like this:

8

click OK to continue

13

Run the Program

n To execute your program click the menu item

! Start Without Debugging

14

/* Hello program */

#include <stdio.h>

int main() { printf( "Hello!\n"); return 0; }

Hello.c: Line by Line

15

Hello.c: Line by Line

/ Hello program /

n /* … */ marks a comment block

n Anything in comments is ignored by the compiler

n Extremely useful for including explanatory information

n You can add comments anywhere in a program

16

Hello.c: Line by Line

#include <stdio.h>

n #include n a C preprocessor command n lets you include the code from another file (such as a library) n stdio.h n the standard input-output library n < > means the file stdio.h is in C library directory n “ ” means the file is in the current directory n #include <stdio.h> n allows you to use code from the standard I/O library

17

Hello.c: Line by Line

int main() { ... } n It is a function, only one main function in each program n Curly brackets { } mark the start and the end of the function n Statements of a function are enclosed in { } n Program execution begins at main() n Empty () means main function has no argument. You may also use int main (void) n int means the main function returns an integer. Don't be too concerned about what this means.

18

Hello.c: Line By Line

printf(“Hello!\n”); return 0; }

n Statements of the main function n All statements are terminated by a semicolon n Statements are executed in sequence, from top to bottom

19

Hello.c: Line by Line

printf( "Hello!\n");

n A function defined in stdio.h

n Prints out the message “Hello!” to the screen n “Hello!\n” is a string consisting of a series of characters n \n is a new line character n begin a new line of text after the message

20

Hello.c: Line by Line

return 0;

n Terminates the execution of main() n Indicates that main() returns the value 0