본문 바로가기

프로그래밍 언어

이클립스로 C프로그래밍 설정하고 개발연습 시작 가이드

728x90

c언어를 참 오래간만에 설정한다.  

갑자기 아들이 아빠 학교에서 C 프로그래밍을 배웠는데 아빠는 할 줄 아는지 물어본다. 음...

그럼 아빠가 하는거 함 보여줘. 음... 그렇다면 일단 설치하고 hello world 정도는 금방 실행해 볼 수 있지...

Visual Studio 2019 실행하여 C#, C++로 콘솔 프로젝트를 만들어서 Hello World 간단하게 실행하여 보여준다.

그리고 마지막으로 이클립스 실행하여 Java로 다시 Hello World 출력하여 3가지 정도 간단하게 보여준다. 

프로젝트 생성하고 컴파일 하고 출력하는데 얼마 안 걸리니 잠깐을 설명을 하면서 10분 안에 보여준다.

ㅎㅎㅎ 어때 아빠 개발자 맞지? 

근데 이제 시작인거지... 그럼 나 c프로그램 간단하게 가르쳐줘요. 그래서 가르쳐줄 맘으로 글을 써본다. 

 

1. 먼저 이클립스를 설치 합시다. C, C++용으로 설치합니다.

2. 이클립스 설치를 하고 C 프로젝트를 시작합니다.

3. 그랬더니 이렇게 오류가 발생을 합니다. 왜냐하면 컴파일러가 설치가 안되었거든요.

4. 그럼 이제 컴파일러를 다운받아서 설치합니다.

sourceforge.net/projects/mingw/

 

MinGW - Minimalist GNU for Windows

Download MinGW - Minimalist GNU for Windows for free. A native Windows port of the GNU Compiler Collection (GCC) This project is in the process of moving to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the G

sourceforge.net

5. 설치했으니 환경변수를 설정합시다.

프롬프트 실행 확인

그리고 다시 이클립스를 실행합니다.

컴파일하고 실행하려면 아래처럼 설정이 필요합니다.

여기까지 똑같이 따라 합니다. 

마우스 우클릭해서 똑같이 실행을 해봅니다.

실행 결과  아래처럼 출력이 되면 성공입니다.

 

이제부터가 진짜 시작이니 다른 예제 프로그램을 직접 타이핑하여 테스트 실행해 봅니다.

숙제....

1. 따라 하기 예제 1

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>

int main(int argc, char** argv) {

    printf("CHAR_BIT    :   %d\n", CHAR_BIT);
    printf("CHAR_MAX    :   %d\n", CHAR_MAX);
    printf("CHAR_MIN    :   %d\n", CHAR_MIN);
    printf("INT_MAX     :   %d\n", INT_MAX);
    printf("INT_MIN     :   %d\n", INT_MIN);
    printf("LONG_MAX    :   %ld\n", (long) LONG_MAX);
    printf("LONG_MIN    :   %ld\n", (long) LONG_MIN);
    printf("SCHAR_MAX   :   %d\n", SCHAR_MAX);
    printf("SCHAR_MIN   :   %d\n", SCHAR_MIN);
    printf("SHRT_MAX    :   %d\n", SHRT_MAX);
    printf("SHRT_MIN    :   %d\n", SHRT_MIN);
    printf("UCHAR_MAX   :   %d\n", UCHAR_MAX);
    printf("UINT_MAX    :   %u\n", (unsigned int) UINT_MAX);
    printf("ULONG_MAX   :   %lu\n", (unsigned long) ULONG_MAX);
    printf("USHRT_MAX   :   %d\n", (unsigned short) USHRT_MAX);

    return 0;
}

2. 따라 하기 예제 2

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>

int main(int argc, char** argv) {

    printf("Storage size for float : %d \n", sizeof(float));
    printf("FLT_MAX     :   %g\n", (float) FLT_MAX);
    printf("FLT_MIN     :   %g\n", (float) FLT_MIN);
    printf("-FLT_MAX    :   %g\n", (float) -FLT_MAX);
    printf("-FLT_MIN    :   %g\n", (float) -FLT_MIN);
    printf("DBL_MAX     :   %g\n", (double) DBL_MAX);
    printf("DBL_MIN     :   %g\n", (double) DBL_MIN);
    printf("-DBL_MAX     :  %g\n", (double) -DBL_MAX);
    printf("Precision value: %d\n", FLT_DIG );

    return 0;
}

3. 따라 하기 예제 3

#include <stdio.h>

// Variable declaration:
extern int a, b;
extern int c;
extern float f;

int main () {

   /* variable definition: */
   int a, b;
   int c;
   float f;
 
   /* actual initialization */
   a = 10;
   b = 20;
  
   c = a + b;
   printf("value of c : %d \n", c);

   f = 70.0/3.0;
   printf("value of f : %f \n", f);
 
   return 0;
}

4. 따라 하기 예제 5

#include <stdio.h>
 
/* function declaration */
void func(void);
 
static int count = 5; /* global variable */
 
main() {

   while(count--) {
      func();
   }
	
   return 0;
}

/* function definition */
void func( void ) {

   static int i = 5; /* local static variable */
   i++;

   printf("i is %d and count is %d\n", i, count);
}

 

그럼 C 프로그램 온라인 강의를 찾아서 들어보거나 온라인 튜토리얼을 함 봅시다.

이클립스 설치하지 않고도 웹브라우저에서 바로 실행이 가능하며 테스트할 수 있어서 학생들이 공부하기 쉬운 사이트입니다.

www.learn-c.org/

 

Learn C - Free Interactive C Tutorial

Welcome Welcome to the learn-c.org free interactive C tutorial. Whether you are an experienced programmer or not, this website is intended for everyone who wishes to learn the C programming language. There is no need to download anything - Just click on th

www.learn-c.org

Start Exercise 버튼을 클릭하면 웹에서 코드를 타이핑하고 바로 결과를 확인할 수 있습니다. 

공부하기 쉽죠?

테스트 결과

그럼 코딩 연습 열심히 해보세요. 파이팅!!!

 

728x90