32
1 Kichun Lee Department of Industrial Engineering Hanyang Univesity GEN1031 Computer Programming DOS Window Command Prompt 사용하여 Hello World! in C Lecture 1

Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

1

Kichun LeeDepartment of Industrial Engineering

Hanyang Univesity

GEN1031Computer Programming

DOS Window Command Prompt을사용하여

Hello World! in C

Lecture 1

Page 2: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

과목 Overview

목적: 본 과목은 C 언어를 통하여 컴퓨터를 이용한공학적 문제 해결 과정을 학습한다.

C 언어의 변수 타입, 제어문, 함수, 포인터, 구조체등을 학습한다.

C 언어와 다른 언어와의 통합의 방법에 대해배운다.

2

Page 3: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

과목 Overview

교재

Engineering Problem Solving with C (4th Edition); Delores M. Etter; Pearson; ISBN 13: 978-0-13-608531-7

C언어 스케치; 강환수, 이동규, 최재승, Infinity Books, ISBN 978-89-92649-62-9

3

Page 4: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

과목 Overview

4

Week Content1 Introduction, Engineering Problem Solving2 Simple C Program: Variable, Type3 Simple C Program: Operator, Input/Ouput4 Control Structure5 Data Files6 Modular Programming with Functions: Function7 Modular Programming with Functions: Macro,

Recursion8 Midterm Exam9 Array and Matrices

10 Searching and Sorting11 Programming with Pointers12 Programming with Pointers13 Programming with Structures14 Introduction to C++/VBA15 Integration of Programs, Further Topics16 Final Exam

1. 거의 매주 숙제 T_T;

2. 진도 내용에 대한 숙제 + 간단한 게임 만드는 프로젝트

3. Late Submission은 시간당10%점수 차감모범 답안 올라간 후에는 0점

4. 본 과목은 녹화전용으로 진행되며, 보통 1시간 강의와 나머지는 숙제진행 및 실습(조교 문의 가능)

조교: 이

Page 5: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

과목 Overview

5

평가항목 비율 평가항목 비율

출석 5% 퀴즈 0%

과제 20% 중간고사 25%

토론 0% 기말고사 35%

팀프로젝트 14% 학습참여도 1%

1. 출석은 online 출석 체크 + offline 출석 체크(호명 and/or 종이)

2. 과제 출제와 제출은 Hyin을 통하여

3. 팀프로젝트는 간단게임 구현 and/or 프로그램통합 숙제로 진행

4. 학습참여도는 Good 수업 summary와 comment, question 등 대하여 부여

Page 6: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

과목: 컴퓨터프로그래밍, 2015 봄이름: 홍길동학번: 2015012345목표: 나는이과목에서무엇을하고싶고,

나는누구이며, 등등등

과목 Overview: HW0, 다음시간에준비해오기

6

이부분을본인내용으로바꾸고손으로적어오기

본인사진넣기 3/3(화): 오늘은 C 언어에서무엇을배웠다. 이런것을생각해보았다. 등등

3/5(목): 오늘은 C 언어에서무엇을배웠다. 이런것을할수있을거라생각했다. 이것이궁금하다. 등등

….

이부분은매번수업마치고적어서제출

수업시간전에본인sheet 찾아가기

Page 7: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

과목 Overview

7

컴퓨터프로그래밍을 왜 배워야 하나?

어떻게 하면 컴퓨터프로그래밍을 잘 할 수 있나?

Page 8: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Hello World! Program in Windows

Microsoft Visual C++ Express 2008(free) 설치

http://www.microsoft.com/express/vc/ Hello World! 프로그램 작성 프로그램을 윈도우에서 컴파일 및 실행

DOS Window Command Prompt을 이용한간단한 방법으로 실행

IDE 또는 Linux/Unix를 사용하는 것도 가능하다.

8

Page 9: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Hello World! Program in Windows

9

Page 10: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Hello World! Program in Windows

10

Page 11: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Hello World! in DOS Window

시작모든프로그램

Microsoft Visual C++ Express 2008 Visual Studio Tools Visual Studio 2008 Command Prompt

11

This black window is calledDOS window

command prompt

Page 12: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Hello World! in DOS Window

12

For Windows 7

Page 13: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Hello World! in DOS Window

도스창에 작성

C:\Program Files…> Z:Z:\> mkdir myprogZ:\> cd myprogZ:\myprog> notepad hello.c

여러분이 파일을 만들고자

할 때, hello – 메모장을이용할 수 있다. 클릭 예(Y)!

13

At home, type cd C:\

Page 14: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Hello World! in DOS Window

hello – 메모장을 이용 프로그램 작성 및 저장

다음으로, 도스창으로 이용해서

다음 명령어를 작성

Z:\myprog> cl hello.cZ:\myprog> helloHello World!

14

Page 15: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

시작 모든 프로그램 Microsoft Visual C++ Express 2008 Visual Studio Tools Visual Studio 2008 Command PromptC:\Program Files…> Z:Z:\> cd myprogZ:\> mkdir ex1Z:\> cd ex1Z:\myprog\ex1> notepad myname.c

myname – 메모장에 프로그램을 작성 컴파일 및 실행

Z:\myprog\ex1> cl myname.cZ:\myprog\ex1> mynameTurgay Korkmaz 15

At home, type cd C:\

Exercise: Develop a program that prints your name on the screen

Page 16: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Save/Print results from the DOS window (black one):

도스창에 작성

Z:\myprog\ex1> notepad output.txt 도스창에서 마우스 우클릭

표시(K)를 선택 출력하길 원하는 결과물을 드래그로 표시 함

Enter 키를 입력 이전에 생성했던 메모장(output.txt)으로 마우스 커서를이동

앞서 표시했던 영역을 output.txt에 붙여넣기를 실행 메모장에 저장 및 작성

16

Page 17: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

See your files in Windows and submit your program

C source file(hello.c)과output.txt 파일을Hyin을 통해 제출

C source file은마우스 우클릭을사용 – 연결프로그램(H) -> 메모장

17

윈도우 탐색기를 열고 다음의주소값을 Z:₩myprog or C:₩myprog 입력

Page 18: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Test HW

여러분 자신의 소개를 출력하는 프로그램을작성하세요.

위의 프로그램을 test1.c로 저장하고, 컴파일 및 실행

결과물을 output1.txt에 복사/붙여넣기

test1.c 및 output1.txt 파일을 HYin 을통해 제출하십시오.

18

Page 19: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

19

/* 추가 연습 문제: 다음 프로그램을 실행시키세요. 어떤 결과를 나타내나요? */

#include <stdio.h>#include <stdlib.h>int main(){double tC; /* temperature in Centigrade */double tF; /* temperature in Fahrenheit *//** Prompt for centigrade temperature*/printf("Centigrade 온도를 넣어보세요: ");scanf("%lf", &tC);/** Convert it to Fahrenheit*/tF = 9.0 * tC / 5.0 + 32.0;

printf("%.2f Centigrade 온도는 %.2f Fahrenheit 와 같습니다.₩n", tC, tF);

return 0; /* signal normal end of program */}

Page 20: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

윈도우에서 C 프로그램을컴파일하기위해서는, Microsoft Visual Studio or Microsoft Visual C++ 2008 Express IDE(integrated development environment)를사용할수있습니다. 이것은프로그래머에게좀더종합적인도구가될것입니다. IDE는 source code editor, a compiler, debugger 등으로구성되어있습니다. 수업시간에는프로그램을작성하고컴파일하기위해도스창을이용할것입니다!! 그러나만약에 IDE를사용하는것에관심을가지고있다면, 여기에이용방법이있습니다. 만약에 IDE에관심이없다면이슬라이드를넘겨도좋습니다.

1. 선택 Start -> All Programs -> Microsoft Visual C++ 2008 Express Edition 2. IDE 메뉴에서 File -> New -> Project 3. dialog box 에서 : 선택 - Win32, Win32 Console Application, 프로젝트 이름 입력 (e.g.,

HW1), 클릭 OK 4. Win32 Application Wizard 나타남. 클릭 Next, 표시/선택 Empty Project, 클릭 Finish 5. IDE 메뉴에서 Project -> Add new item 6. dialog box 에서 : 선택 C++ File, 파일 이름 입력 (e.g., HW1.c), 클릭 Add 7. HW1.c 에 당신의 C 프로그램을 입력/편집. 완료 후 저장 8. 지금 당신은 프로그램을 다음과 같이 컴파일 해야 함 9. IDE 메뉴에서 Build -> Built Solution 10. 컴파일러는 IDE의 새로운 창에 결과물을 보여줌 11. 만약에 어떠한 오류가 있다면 7단계로 이동해서 프로그램을 수정하고 다시 컴파일을 실시 12. 만약에 오류가 없다면, 당신은 다음과 같이 프로그램을 운영할 수 있음 13. IDE 메뉴에서 Debug -> Start without debugging 14. 도스창에서 결과물을 얻을 수 있고 또한, 입력 값을 얻을 수 있음 15. 프로그램을 출력하기 위해, IDE 메뉴에서 File -> Print

20

Page 21: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Hello World! Program in Windows

21

For Windows 7

Page 22: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

22

Trouble Shooting

VC++ Express IDE를사용하여 Compile 할때에 아래와 같은 에러가발생할 수 있다

Page 23: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

23

Trouble Shooting

Page 24: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

24

Trouble Shooting

Page 25: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

25

Trouble Shooting

Page 26: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

26

Trouble ShootingSimilarly, when IDE faces ‘scanf’-related error codes:'scanf': This function or variable may be unsafe.Consider using scanf_s instead…https://www.youtube.com/watch?v=p5HKz_Zi3n0

일반 cmd 창에서 cl.exe 등을 사용할 때에D:₩classes₩ConsoleApplication1₩Debug>set PATH=%PATH%;"C:₩Program Files (x86)₩Microsoft Visual Studio 12.0₩VC₩bin"

obj 파일에서 exe 파일을 만들려고 할 때에LINK /OUT:MyTest.exe TemperatureConvert.obj

Page 27: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

Hello World! in Linux (or Cygwin)Similar to DOS Window. If you plan to use Linux, I can give you more instructions. Just ASK. But, if you are not interested in Linux, SKIP this slide!

Login to a linux machine SSH Secure Shell (e.g., main212.cs.utsa.edu)main212:> mkdir myprogmain212:> cd myprogmain212:> pico hello.c

Type your program … and save it (ctrl-o) Compile and execute your program

main212:> gcc hello.c –o hellomain212:> hello

27

Page 28: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

28

Cygwin_Downloadhttps://cygwin.com/install.html

32-bit

64-bit

- Window환경에서 Linux를 사용하도록 도와주는 도구

Page 29: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

29

Cygwin_Install

패키지 설치1.Gcc 검색 – Devel – gcc-ada : GNU Compiler Collection(Ada)

– gcc-ada : GNU Compiler Collection(C, OpenMP)2. Vim 검색 – Editor – gvim : GUI for the Vim text editor

- vim : Vi Improved –enhanced vi editor- vim-common : Vi Improved

(1) 패키지검색

(2) New 항목에서 버전 이름이 표시되게 클릭

Page 30: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

30

Cygwin PATH내 컴퓨터 마우스 우클릭 -> 고급 -> 환경 변수

• 경로 추가1. “시스템 변수” 내에 있는

“Path”를 선택한 후“편집” 버튼을 클릭

2. “변수 값” 항목의 가장앞에 cygwin 이 설치된경로를 추가

3. C:₩Program Files₩cygwin 에 설치가되어 있다면C:₩Program Files₩cygwin₩bin; 을입력

Page 31: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

31

Cygwin_C Coding

$ gcc-version 입력 ## gcc 패키지 설치 확인$ vim hello.c ## vi편집기를 이용해 hello.c 작성$ gcc hello.c –o hello ## gcc로 빌대해서 hello.exe 실행파일 만들기$ ./hello.exe ## hello.exe 실행

Vi 편집기

저정후 종료 명령어

Page 32: Lecture 1contents.kocw.net/KOCW/document/2015/hanyang/leekichun/0.pdf · 2016-09-09 · 팀프로젝트 14% 학습참여도 1% 1. 출석은online 출석체크+ offline 출석체크(호명and/or

32

Cygwin_Vi 문서편집기

명령어 동작

a 편집모드 진입 : 현재 커서 뒤부터 입력 <-> ii 편집모드 진입 : 현재 커서 앞에서 입력 <-> a

h,j,k,l 커서 이동

d 현재 커서의 행 삭제 or 잘라 내기u 삭제취소

:q 저장 없이 종료

:wq 파일 저장 후 종료 (위와 같음)

명령모드

- vi의 기본모드인 입렵모드에서 esc키를 누른 경우커서이동, 문자열 수정 등 엔터키를 사용할 필요 없이각각의 명령에 따라 바로 실행 됨

입력모드

- 내용을 입력할 수 있는 모드 하단에 –INSERT-라고표시되고 명령상태에서 a, i, o키를 누르면 진입