“Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12....

31
“Hello World!” Using Bloodshed Dev-C++ on Windows and GCC on Linux Taesoo Kwon Heejin Park Hanyang University

Transcript of “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12....

Page 1: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

“Hello World!”Using Bloodshed Dev-C++ on Windows

and GCC on Linux

Taesoo Kwon

Heejin Park

Hanyang University

Page 2: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Introduction

Installing Dev-C++

Starting the Dev-C++

A Simple Example of Dev-C++

• Simple program 1

• Simple program 2

• Simple program 3

Write the first program

• "Hello world"

2

Page 3: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Introduction to Dev-C++

Dev-C++

• Write and compile C++ programs.

• Full featured IDE(Integrated Development Environment).

• Support GCC based compilers.

Dev-C++ programming

• Need to install software: Bloodshed Dev-C++• Free C++ compiler and development environment.

• It can also handle the Insight Debugger.

• Another good free alternative is Microsoft Visual Studio Express.

• (Visual Studio Express in free only for home users.)

3

Page 4: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Installing Dev-C++

Download Dev-C++

• Official website: http://www.bloodshed.net/dev/devcpp.html

• Download Dev-C++: devcpp-4.9.9.2_setup.exe

4

Page 5: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Installing Dev-C++

Install Dev-C++

5

Page 6: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Bloodshed Dev-C++ 4.9.9.2

Starting the Bloodshed Dev-C++

6

Page 7: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Bloodshed Dev-C++ 4.9.9.2

Starting the Bloodshed Dev-C++

7

Page 8: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Bloodshed Dev-C++ 4.9.9.2

• Execute a program.

• choose Execute > Compile & Run or just press the F9 key.

Starting the Bloodshed Dev-C++

8

Page 9: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Page 9

VirtualBox 에 Ubuntu 12.04 LTS 설 치(Windows 안 에 가 상 으 로 Ubuntu 설 치 하 는 법 )

Ubuntu Desktop 최신 버전 받기 (32-bit) http://www.ubuntu.com/getubuntu/download

VirtualBox 에서 우분투 (Ubuntu) 용 가상머신 만들기

– http://www.psychocats.net/ubuntu/virtualbox

– http://www.deltalounge.net/wpress/2012/06/virtualbox-install-ubuntu-12-04/

기본설정에서는 가상 머신의 해상도가 모니터 해상도와 달라서 불편함 .

– 해결 방법

– Download the guest edition for your virtualbox version!

– 버젼 .1.20 을 가정하면

● visit http://download.virtualbox.org/virtualbox/4.1.20/

● download VBoxGuestAdditions_4.1.20.iso

– 게스트 에디션 설치

– http://www.dedoimedo.com/computers/virtualbox-guest-addons.html

– (see “Install Guest Additions on Linux guest” section)

Page 10: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Page 10

GCC 설 치 (UBUNTU 기 준 )

sudo apt-get install gcc

– (gcc 자체를 인터넷에서 받아와 설치함 )

sudo apt-get install build-essential

– (gcc 를 제대로 사용하기 위해 관련 라이브러리 설치 )

3/25/13

Page 11: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Page 11

– 개 발 환 경 gcc

Source codeProgram

name

gcc 를 이용한 Source code 컴파일

g++ -o Test test.cpp

gcc –o Test Test.c

#include <iostream>int main() {

std::cout << "Hello\n";}

test.cpp

Page 12: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Page 12

Let's learn Unix shell commands(These days, everybody uses GUI.But shell commands are still absolutely useful for programmers!)

● ls

● ls -l

● mkdir ttt

● cd ttt

● rm abc

● cd ~

● cat abc

● find . -iname “*.txt”

● grep “asdf” *.txt

● vim a.txt

● gedit a.txthttp://freeengineer.org/learnUNIXin10minutes.html

디 렉 토 리 변 경

파 일 목 록

디 렉 토 리 만 들 기

홈 디 렉 토 리 로 이 동

파 일 보 기

파 일 삭 제

여 러 파 일 에 서 문 자 열 검 색

하 위 디 렉 토 리 에 서 파 일 찾 기

Page 13: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Basic Structure

• #include• Include another file.

• int main()• Always the first function called.

• Statements• Declaration

• Assignment

• Function

• Control

• Null

Starting the C language

13

Page 14: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Simple program1

A Simple Example

14

Page 15: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Simple program1

• Source code

A Simple Example

15

system(“read one'”); // 리 눅 스 에 서 는 pause 명 령 대 신 read 명 령 을 사 용 할 것

Page 16: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Code explanation

• Comment• Just reminds us what this program does.

A Simple Example

16

/* Simple program(1) */

// Simple program(1)

Page 17: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Code explanation

• Header file

• Standard buffered input/output.

• Most of the C file input/output functions are defined in stdio.h.

• Standard library definitions.

A Simple Example

17

#include <stdio.h>

#include <stdlib.h>

Page 18: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Code explanation

• Printf() function

• Stop the console window

A Simple Example

18

printf("I am a simple");printf("Computer.\n");printf("My favorite number is %d because it is first.\n", num);

system("PAUSE");

Page 19: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Simple program2

A Simple Example

19

Page 20: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Simple program2

• Source code

A Simple Example

20

Page 21: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Code explanation

• Using operator

• Multiplication

A Simple Example

21

int feet, fathoms;fathoms = 2;

feet = 6 * fathoms

Page 22: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Simple program3

A Simple Example

22

Page 23: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Simple program3– Source code

A Simple Example

23

Page 24: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Code explanation

• Using scanf()

• Read formatted string, character, or numeric data from a file.

• "%c"

– Interpret input as a character.

• If you use scanf() to Read a string into a character array

– don’t use an &

A Simple Example

24

int a; scanf("%c", &variablename);

Page 25: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Code explanation

• ANSI C Conversion specifiers for scanf()

A Simple Example

25

Conversion Speci-fier

Meaning

%c Interpret input as a character

%d Interpret input as a integer

%e, %f, %g, %a Interpret input as a floating-point number

%o Interpret input as a unsigned octal inte-ger

%p Interpret input as a pointer (an address)

%s Interpret input as a string

Page 26: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Write the first program “Hello World!”

Python program “Hello World!”

26

Page 27: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Write the first program “Hello World!”

Quiz

• Convert Python program to Dev-C++ program.

27

Page 28: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Write the first program “Hello World!”

Programs “Hello World!”

• Python source code

• Dev-C++ source code

28

Page 29: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Write the first program “Hello World!”

Programs “Hello World!”

• Python source code

• Dev-C++ source code

29

Page 30: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Write the first program “Hello World!”

Programs “Hello World!”

• Python source code

• Dev-C++ source code

30

Page 31: “Hello World!” - Hanyangcalab.hanyang.ac.kr/courses/ISD_taesoo/C01.Hello_World.pdf · 2014. 12. 21. · "Hello\n";} test.cpp. Page 12 Let's learn Unix shell commands (These days,

Write the first program “Hello World!”

Programs “Hello World!”

• Dev-C++ source code

31