1. 구조체 사용과정 (3단계)

  1. main 함수 위에 구조체를 정의함.
  2. main 함수 내에 구조체 변수를 선언함.
  3. 구조체의 맴버를 참조.
2. 구조체 변수를 이용한 예(소스, 결과, 주석)

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

//1. main 함수 위에 구조체 정의
struct person
{
char id[6];
char name[10];
char tel[14];
int grade;
};

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

//2. 사용자 정의 자료형 : 구조체 변수 선언
struct person members;
printf("학번 : ");
scanf("%s", members.id);
 
printf("이름 : ");
scanf("%s", members.name);
 
  printf("전화 : ");
scanf("%s", members.tel);
printf("등급 : ");
scanf("%d", &members.grade);
printf("이름 : %s, 번호 : %s, 등급 : %d", members.name, members.tel, members.grade);

system("pause");
return 0;
}




3. 구조체 배열을 이용한 예(소스, 결과, 주석)

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

//1. main 함수 위에 구조체 정의
struct person
{
char id[6];
char name[10];
char tel[14];
int grade;
};

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

//2. 사용자 정의 자료형 : 구조체 배열 선언
struct person members[3];
int i;
for(i=0;i<3;i++)
{
printf("학번 : ");
scanf("%s", members[i].id);
 
printf("이름 : ");
scanf("%s", members[i].name);
 
  printf("전화 : ");
scanf("%s", members[i].tel);
printf("등급 : ");
scanf("%d", &members[i].grade);
}
for(i=0;i<3;i++)
{
printf("\n 이름 : %s, 번호 : %s, 등급 : %d \n", members[i].name, members[i].tel, members[i].grade);
}


system("pause");
return 0;
}





20161126main1.c

main_ver2.c

ForOreport.dev

ForOreport.exe

ForOreport.layout

Makefile.win

report.c

report.o

main_ver2.c


'basic > C' 카테고리의 다른 글

7. 포인터  (0) 2016.11.10
6. 함수  (0) 2016.10.31
5. 배열  (0) 2016.10.13
4. 제어문(조건문과 반복문)  (0) 2016.10.06
3. 연산자  (0) 2016.09.22

1. 포인터의 개념

데이터가 저장된 주기억장치의 주소만 저장 (갂단히 포인터(pointer)라고도 함)


2. 포인터와 배열의 관계 예(소스코드,실행결과)


#include <stdio.h>

#include <stdlib.h>

#define N 4


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


//void print_arr(int arr[]); //3. 함수의 원형 선언 

void print_arr(int *arr);


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

int count[N] = {42, 37, 83, 33}; // 배열이름 = 시작주소 

//1. 출력할 함수의 이름 정의

print_arr(count); 

return 0;

}


//2. 함수 구현

//void print_arr(int arr[]) //int arr[N]배열을 다시 선언하면서 받는다. 

void print_arr(int *arr) //배열의 주소가 넘어오므로 포인터로 받는다. 

{

int i;

for(i=0;i<N;i++) 

printf("%3d", *(arr+i));

//printf("%3d", arr[i]);



3. 포인터를 이용한 문자열 교환 예제


#include <stdio.h>

#include <stdlib.h>

#define SIZE 5


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


char *first = "GilDong", *last = "Hong"; // 이름 , 성 

char *temp;   // 임시 저장 포인터 변수 

   

printf("Name : %s %s \n", first, last);

    

   

   // 포인터 변수에 저장된 두 주소를 교환해 두 포인터가 가리키는 문자열 교환하기

   

temp = first;

first = last;

last = temp;

   

printf("Name : %s %s \n ", first, last); 



   return 0;

}




4. char형 배열을 이용한 문자열 교환 예제


#include <stdio.h>

#include <stdlib.h>

#define SIZE 5


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


 char first[10] = "GilDong", last[10] = "Hong"; // 이름과 성

   char temp[10]; // 문자열을 임시로 저장할 배열


   printf("Name : %s %s\n", first, last);


 // 배열의 내용을 직접 교환하여 두 문자열을 교환하기

   strcpy(temp, first); // first 배열의 문자열을 temp 배열에 복사하기

   strcpy(first, last); // last 배열의 문자열을 first 배열에 복사하기

   strcpy(last, temp); // temp 배열의 문자열을 last 배열에 복사하기

   

   printf("Name : %s %s \n", first, last);



   return 0;

}




5. char형 2차원 배열을 이용한 정렬 예제


#include <stdio.h>

#include <stdlib.h>

#define SIZE 5


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


char silver[SIZE][10] = {"나태희","유빈","나원빈","문건영","소지법"};

char temp[10];

int i, pass; 

printf("**은메달 리스트 ");

for(i=0;i<SIZE;i++)

printf("%s, ", silver[i]);

printf("\b\b **\n\n");

for(pass=1;pass<SIZE;pass++)

for(i=0;i<SIZE-pass;i++)

if(strcmp(silver[i], silver[i+1]) > 0 )

{

strcpy(temp, silver[i]);

strcpy(silver[i], silver[i+1]);

strcpy(silver[i+1], temp);

}

printf("**정렬한 리스트 ");

for(i=0;i<SIZE;i++)

printf("%s, ", silver[i]);

printf("\b\b **\n\n");


   return 0;

}




6. char형 포인터배열을 이용한 예제


#include <stdio.h>

#include <stdlib.h>

#define SIZE 5


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


   char *gold[5] = {"한빛","성춘향","이몽룡","사공민국","황해"};

   char *temp;

   int size, i, j;

   

   size = sizeof(gold) / sizeof (gold[0]);

   

   printf("** 금메달 리스트 : ");

   for(i=0;i<size;i++)

      printf("%s, ", gold[i]);

      printf("\b\b ** \n\n");

   

   for(i=0;i<size;i++)

      for(j=i+1;j<size;j++)

         if(strcmp(gold[i], gold[j]) > 0 )

         {

            temp = gold[i];

            gold[i] = gold[j];

            gold[j] = temp;

         }

   

   printf("** 정렬한 리스트 : ");

   for(i=0;i<size;i++)

      printf("%s, ", gold[i]);

      printf("\b\b ** \n\n");


   return 0;

}




'basic > C' 카테고리의 다른 글

8. 구조체  (0) 2016.11.21
6. 함수  (0) 2016.10.31
5. 배열  (0) 2016.10.13
4. 제어문(조건문과 반복문)  (0) 2016.10.06
3. 연산자  (0) 2016.09.22

1. 함수의 필요성 : : 하나의 큰 문제들을 작은 문제로 쪼개어 해결함에 용이하여 사용함.


2 c함수의 종류


(1) 라이브러리 함수


예제1 : 기본적인 rand()함수 소스코드, 실행결과


rand()함수 : 0~32767 범위 안의 임의의 정수를 결과 값으로 호출


문제점 : 컴파일 시켰을때 동일한 값이 출력됨


#include <stdio.h>

#include <stdlib.h>

#include <time.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int i,random;

for(i=1;i<=5;i++)

{

random = rand();

printf("%d번째 난수 %5d \n",i ,random);

}

return 0;

}




예제2 : 범위를 지정한 rand()함수 소스코드, 실행결과


#include <stdio.h>

#include <stdlib.h>

#include <time.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int i,random;

for(i=1;i<=5;i++)

{

random = rand()%6+1;

printf("%d번째 난수 %5d \n",i ,random);

}

return 0;

}




예제3 : 씨드값 설정한 rand()함수 소스코드, 실행결과


#include <stdio.h>

#include <stdlib.h>

#include <time.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int i,random;

srand(time(NULL));

for(i=1;i<=5;i++)

{

random = rand();

printf("%d번째 난수 %5d \n",i ,random);

}

return 0;

}




(2) 사용자 정의함수


정의하는 순서 예제


{1} main() 함수이름 정의


(2) main() 밖 아래 함수기능 정의


(3) main() 밖 위 함수의 원형 정의

아직 정리중인 내용...


(3) 인수 : main에서 넘어가는 값


(4) 매개변수 : 넘어오는 값을 받는 변수


*main()에서 함수호출시 인수를 전달하고 정의된 함수에서 매개변수를 선언하면서 받는다.


3. 함수의 인수전달 방법


(1) 값에 의한 호출 (call by value) 예제(소스코드,실행결과)

main안의 변수 그 안의 인수를 함수(매개변수공간)에 그대로 호출하여 입력. 

원본과 복사본이 서로 독립된 공간을 가짐 여기서 원본은 main공간 안의 인수를말하고 복사본은 사용자 지정 함수안에서의 매개변수 공간을 말함.


#include <stdio.h>

#include <stdlib.h>


void sort_by_point(int first, int second); // 함수 원형정의 


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int point1=5000, point2=4000;

printf("함수 호출전 포인트 점수 %d, %d\n", point1, point2);

sort_by_point(point1, point2); // 값에 의한 호출. 

printf("함수 호출후 포인트 점수 %d, %d\n", point1, point2);

return 0;

}


void sort_by_point(int first, int second) //함수정의 : 값에 의한 호출


{

int temp;

if(first>second)

{

temp=first;

first=second;

second=temp;

}

printf("\n sort함수 안에서 정렬한 결과 first : %d, second : %d\n\n", first, second);

}




(2) 주소에 의한 호출 (call by address) 예제(소스코드,실행결과)


#include <stdio.h>

#include <stdlib.h>


void sort_by_point(int *first, int *second); // 함수 원형정의 


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int point1=5000, point2=4000;

printf("함수 호출전 포인트 점수 %d, %d\n", point1, point2);

sort_by_point(&point1, &point2);   // 주소에 의한 호출. 

printf("함수 호출후 포인트 점수 %d, %d\n", point1, point2);

return 0;

}


void sort_by_point(int *first, int *second) //주소에 의한 호출 

{

int temp;

if(*first>*second)

{

temp=*first;

*first=*second;

*second=temp;

}

printf("\n sort함수 안에서 정렬한 결과 first : %d, second : %d\n\n", *first, *second);

}




4. 값에 의한 호출의 문제점과 주소에 의한 호출의 필요성 : 호출된 함수에서 자신을 호출한 함수의 인수 내용을 수정 할 수가 없는 문제점이 있고 호출된 함수에서 자신을 호출한 함수의 인수를 변경하고 싶다면 주소에 의한 호출을 이용해야 함.


5. 배열 원소 함수로 전달하는 방법->설명

(예제, 소스코드, 주석)


#include <stdio.h>

#include <stdlib.h>


//3. 함수의 원형을 작성 

int find_large(int first, int second);


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


// 배열의 원소를 함수로 전달하는 방법

int max, score[5] = {10,8,9,7,8};

//1. 호출할 위치에서 함수이름 정의

max = find_large(score[1], score[2]);

printf("%d, %d중 큰 수는 = %d\n", score[1], score[2], max);

return 0;

}


//2. 함수 작성

int find_large(int first, int second)

{

if (first>second)

return first;

else

return second;




6. 배열 전체를 함수로 전달하는 방법-> 설명

(예제, 소스코드, 주석)


#include <stdio.h>

#include <stdlib.h>

#define N 4


//3. 함수의 원형을 작성한다. 

void print_arr(int arr[N]);

void percentage(int arr[N]);


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

//예제2. 배열전체를 함수로 전달하는 방법

//함수 전달할때는 ~~~ 넘기고, 함수정의할떄는 ~~~ 받는다. 

int count[N] = {42, 37, 83, 33}; 

//1. 함수 이름을 정의한다. 

printf("인원수 : ");

print_arr(count); //배열 이름은 시작 주소를 의미하기 때문에 주소를 넘기면 배열 전체를 넘길수 있다.  

printf("\n");

printf("백분율 : ");

percentage(count); //함수는 배열의 백분율을 계산해서 출력 

print_arr(count);

return 0;

}


//2. 함수를 작성한다. 

void print_arr(int arr[N]) // int arr[]도 가능하다  

{

int i;

for(i=0;i<N;i++)

printf("%3d", arr[i]);

}


// 배열에 저장된 수치를 백분율로 변경하는 함수 

void percentage(int arr[N])// int arr[]도 가능 

{

int i, total = 0;

//전체 인원을 total에 구하기 

for(i=0;i<N;i++)

total += arr[i]; // 배열 전체를 읽으면서 total값 계산 

// 전체 인원수 total을 이용해 백분율 구하기 

for(i=0;i<N;i++)

arr[i] = (int)((double)arr[i]/total*100);

}



'basic > C' 카테고리의 다른 글

8. 구조체  (0) 2016.11.21
7. 포인터  (0) 2016.11.10
5. 배열  (0) 2016.10.13
4. 제어문(조건문과 반복문)  (0) 2016.10.06
3. 연산자  (0) 2016.09.22

1. 배열의  개념 : 자료형이 같은 여러개의 값을 연속된 기억장소에 같은 이름(배열명)으로 저장한것 주로 동일한 구조의 많은 자료등을 다룰때 사용한다.


변수는 하나의 자료를 저장하지만 배열은 여러개의 자료를 저장한다 즉 여러 변수의 모임이라고 볼수있다.


2. 배열 선언 및 주의사항 : 배열을 선언할때에 배열의 크기(배열 원소수)에는 정수형 상수만 가능하고 변수는 불가능하다.


3. 배열의 초기화 : 배열의 크기를 지정하고 초기값이 부족하다면 초깃값은 자동으로 0으로 지정된다. 배열 원소수를 명시 않으면 중괄호{} 안의 값 개수가 원소수로 결정된다.


4. 예제1 - 5명의 퀴즈점수를 배열에 저장한 후 평균 출력하기 프로그램


#include <stdio.h>

#include <stdlib.h>

#define SIZE 5


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

/*

//배열선언 예

//1. 1000명의 나이를 저장하는 배열

int age[1000];

//2. 5명의 퀴즈점수를 저장하는 배열

int quiz[5];

//3. 100명의 평균을 저장하는 배열

double avg[100];

//4. 학생의 이름(홍길동)을 저장하는 배열

char name[10];  

*/


//배열 예제1. 5명의 퀴즈점수를 입력

int quiz[SIZE], i, count;

int sum=0;

double avg;


for(i=0;i<SIZE;i++)

{

printf("퀴즈점수 입력 : ");

scanf("%d", &quiz[i]);

sum+=quiz[i]; //sum=sum+quiz[i];

avg = (double)sum / SIZE;

//입력한 점수의 합을 출력

printf("입력한 %d명의 합 : %d\n", SIZE, sum);

printf("입력한 %d명의 평균 : %.1lf\n", SIZE, avg);

//평균미만인 수

for(i=0;i<SIZE;i++)

{

if(quiz[i] < avg)

count++;

}

//결과출력

printf("===========================\n");

printf(" 번호 점수 평균과의 차이 \n"); 

printf("===========================\n");

for(i=0;i<SIZE;i++)

printf(" %2d     %2d      %5.1lf\n", i+1, quiz[i], quiz[i]-avg);

printf("===========================\n");

printf(" 평균 : %.1lf 점 \n", avg);

printf("===========================\n");

printf(" 평균미만 : %d명 \n", count);

return 0;

}




5. 예제 2 - 배열의 원소에서 최소값, 최대값 구하기


#include <stdio.h>

#include <stdlib.h>

#define N 5

/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int i;

int min, max; //1. min 변수 지정 

int f[N]={3,0,-30,-20,-1};

for(i=0;i<N;i++)

{

printf("%d ", f[i]);

}

printf("\n");

//최소값 찾기

//2.첫번째 원소를 min변수에 저장

min = f[0];

for (i=1;i<N;i++)

{

if(f[i]<min) //3. 각 원소를 min변수와 비교 및 교체작업 

min = f[i];

//최소값 출력

printf("\n\n 최소값은 %d \n", min); 

//최대값 찾기

max = f[0];

for(i=1;i<N;i++)

{

if(f[i]>max)

max = f[i]; 

//최대값 출력

printf("\n\n 최대값은 %d \n", max); 

 

return 0;

}



7. 예제4 - 배열의 원소를 오름차순 정렬 소스코드, 실행결과

             (주석: 오름차순의 개념정리, 버블정렬, 개선된 버블정렬의 원리 및 차이점)


#include <stdio.h>

#include <stdlib.h>

#define SIZE 5


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int a[SIZE] = {5,4,3,2,1};

int repeat, i, temp;

FILE *fp;


printf("정렬 전 배열 : ");

for(i=0;i<SIZE;i++)

printf("%4d",a[i]);

printf("\n");

// 버블 정렬 시작 : 오름차순정렬 

for(repeat=1;repeat<SIZE;repeat++) // (배열 원소수-1)번 반복하기 

{

//배열의 이웃한 두 원소간의 정렬을 차례대로 반복하기 

for(i=0;i<SIZE-repeat;i++) //(i가 0부터 3까지 순서를 반복) 

{ //SIZE-repeat 개선된 이유 : 이미 정렬이 끝난 부분의 비교를 제거하여 실행속도가 빨라짐. 

if(a[i]>a[i+1])

{

temp=a[i];

a[i]=a[i+1];

a[i+1]=temp;//이웃하는 두원소 교환 

}

} //안쪽 for의 끝 

} // 바깥쪽 for의 끝 

  for(i=0;i<SIZE;i++)

printf("%4d", a[i]);

//배열원소 출력 

fp=fopen("asc.txt","w");

        for(i=0;i<SIZE;i++)

fprintf(fp, "오름차순 정렬 : %2d",a[i]);

fclose(fp);

return 0;

}





8. 예제5 - 배열의 원소를 내림차순 정렬 소스코드, 실행결과           

             (주석:  내림차순 개념정리)


#include <stdio.h>

#include <stdlib.h>

#define SIZE 5


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int a[SIZE] = {1,2,3,4,5};

int repeat, i, temp;


printf("정렬 전 배열 : ");

for(i=0;i<SIZE;i++)

printf("%4d",a[i]);

printf("\n");

// 버블 정렬 시작 : 내림차순정렬 

for(repeat=1;repeat<SIZE;repeat++) // (배열 원소수-1)번 반복하기 

{

//배열의 이웃한 두 원소간의 정렬을 차례대로 반복하기 

for(i=0;i<SIZE-repeat;i++) //(i가 0부터 3까지 순서를 반복) 

{ //SIZE-repeat 개선된 이유 : 이미 정렬이 끝난 부분의 비교를 제거하여 실행속도가 빨라짐. 

if(a[i]<a[i+1])

{

temp=a[i];

a[i]=a[i+1];

a[i+1]=temp;//이웃하는 두원소 교환 

}

} //안쪽 for의 끝 

} // 바깥쪽 for의 끝 

  for(i=0;i<SIZE;i++)

printf("%4d", a[i]);

//배열원소 출력 

return 0;

}




'basic > C' 카테고리의 다른 글

7. 포인터  (0) 2016.11.10
6. 함수  (0) 2016.10.31
4. 제어문(조건문과 반복문)  (0) 2016.10.06
3. 연산자  (0) 2016.09.22
2. C프로그래밍의 기초문법  (0) 2016.09.08

1. 조건문 - if문


1.1 형식1 예제(소스코드, 실행결과)


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int score;

printf("점수입력 : ");

scanf("%d", &score);

//if문 형식1 예제

if(score>=80)

{

printf("점수는 %d, 결과는 ", score);

printf("합격"); 

}

return 0;

}



*텍스트 파일 생성


예제


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int age;

FILE *fp; //1. FILE포인터 선언

 

printf("나이입력 : ");

scanf("%d", &age);

fp=fopen("age.txt", "w"); //2. 생성할 FILE open

fprintf(fp, "나이 : %d",age);//3. file에 내용 쓰기 : fprintf() 

fclose(fp);//4. file 닫기 : fclose() 


return 0;

}



1.2 형식2 예제(소스코드, 실행결과)


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

//if문 형식2

int score;

printf("점수 입력 : ");

scanf("%d", &score); 

if(score>=80)

{

printf("점수는 %d이고, ",score);

printf("합격입니다.\n");

}

else

{

printf("점수는 %d이고, ",score);

printf("불합격입니다.\n");

}

return 0;

}



1.3 형식3 예제(소스코드, 실행결과)

#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


//if문 형식3

int score;

printf("점수입력 : ");

scanf("%d", &score);

if(score >= 90)

printf("A등급\n");

else if(score>=80) //주의 : else와 if사이에 공백이 있어야함. 

printf("B등급\n"); 

else if(score>=70)

printf("C등급\n");

else

printf("F등급\n"); 

return 0;

}



2. 조건문 - switch문 예제


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


int menu;


printf("1. 입금하기 \t 2. 출금하기 \t 3. 송금하기 \n");

printf("메뉴 번호선택 : ");

scanf("%d", &menu);

//주의 : case문 뒤에 반드시 break문을 붙인다. 

switch(menu) //정수형 값 또는 정수형 결과 

{

case 1: printf("입금하기 화면이동...\n"); break; 

case 2: printf("출금하기 화면이동...\n"); break;

case 3: printf("송금하기 화면이동...\n"); break;

default: printf("잘못된 입력입니다. \n");

}

return 0;

}




3. 반복문 - for문 예제

#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


//for문

int i, sum=0;

printf("1. 1~10출력 \n\n");

for(i=1;i<=10;i++) 

printf("%d\n", i);

printf("\n");

printf("2. 10~1출력 \n\n");

for(i=10;i>=1;i--)

printf("%d\n", i); 

printf("\n");

printf("\n------------------\n");

printf("3. 1~10합출력");

for(i=1;i<=10;i++)

{

sum = sum+i; // sum+=i;

}

printf("합 = %d\n", sum);

printf("\n");

printf("4. 1~10중 3의 배수 출력\n\n");

for(i=0;i<=10;i+=3) // i+=3 은 i=i+3과 같음

printf("%d\n", i);

printf("\n------------------\n");

printf("\n");

printf("5. 무한반복 : 합이 1000이 넘는 i값 \n\n");

for(i=1;;i++) //조건식을 생략하면 무한반복됨

{

printf("%d\n",i);

sum+=i;

if(sum>1000) break;

}

printf("합은 %d \n",sum);


return 0;

}



#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


int line, star;

for(line=1;line<=5;line++)

{

for(star=1;star<=line;star++)

printf("*");

printf("\n");

}

for(line=1;line<=5;line++)

{

for(star=5;star>=line;star--)

printf("*");

printf("\n");

}



int i,j;

printf("6. 2중 for문 : 구구단\n\n");

for (i=2;i<=9;i++)

{

for(j=1;j<=9;j++)

{

printf("%d * %d = %d\n",i,j,i*j);

}

printf("\n");

}

return 0;

}





4. 반복문 - while문 예제


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


printf("7. while문 : 1~10출력 \n\n");


//while문 형식

// 1. 초기식

// 2. while문(조건식)

// { 반복실행 문장 

// 3. 증감식 

// }

int i;

i=1; //초기식 

while(i<=10)//조건식 

{

printf("%d\n",i);

i++; //증감식 

}


return 0;

}




5. 반복문 - do~while문 예제


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


printf("8. do~while문 : 1~10출력 \n\n");

//형식

// 1.초기식

//do

// {

// //3.증감식 

// } while(조건식); //2. 조건식 : 세미콜론(;) 붙인다.

int i;

i=1; //1. 초기식

do{

printf("%d\n",i);

i++; //3. 증감식 

} while(i<=10); //2. 조건식 


return 0;

}



'basic > C' 카테고리의 다른 글

6. 함수  (0) 2016.10.31
5. 배열  (0) 2016.10.13
3. 연산자  (0) 2016.09.22
2. C프로그래밍의 기초문법  (0) 2016.09.08
1. C프로그래밍의 기초  (0) 2016.09.05

1. 대입연산자


(1) 종류 : 왼 = 오 (오른쪽에서 왼쪽으로 대입)


(2) 예제 


#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int a = 3, b = 5, temp=0; // 변수 선언  


printf("교환전 : a= %d, b= %d\n", a, b); 

temp=b; //b를 temp에 대입 

b=a; // a를 b에 대입 

a=temp; // temp를 a에 대입 

printf("교환후 : a= %d, b= %d\n",a ,b);

return 0;

}




2. 산술연산자


(1) 종류 : + 더하기     - 빼기     * 곱하기     / 나누기     % 나머지 구하기(정수만 가능) 


(2) 예제1(소스코드, 실행결과, 주석)


#include <stdio.h>

#include <stdlib.h>


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


int a, b;


printf("두개의 숫자를 입력하시오\n");


scanf("%d%d", &a, &b);


printf("%d + %d =%d\n", a, b, a + b);// 더하기 연산

printf("%d - %d =%d\n", a, b, a - b);// 빼기 연산


printf("%d * %d =%d\n", a, b, a*b);// 곱하기 연산


printf("%d / %d =%d\n", a, b, a / b);// 나누기 연산


printf("%d %% %d = %d\n\n", a, b, a%b);// 나머지 구하기



return 0;

}



(3) 예제2 : 형변환 연산 (소스코드, 실행결과, 주석)

#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

char ch = 'A'; // A라는 문자의 아스키 코드값을 저장

 

int x = 10, y = 4, sum = 0; 

double pi = 3.14, avg;

sum = ch + 2; //자동형 넓힘 변환. char형(1byte) 에서 int형(4byte)으로 들어가면서 자동으로 모양이 넓혀짐. 

printf("sum = %d = %c \n", sum, sum);

sum = pi; // 자동형 좁힘 변환. double형(8byte) 에서 int형(4byte)으로 컴파일러가 자동으로 모양을 좁혀서 넣음. 

printf("sum = %d \n", sum);

printf("x/y = %d", x/y); // 정수/정수 = 정수 

// 강제형변환 : 실수/실수 = 실수 

printf("x/y = %lf", (double)x/(double)y); //강제적으로 자료형을 변환시킬수있음 

sum = (double)x/(double)y; // 강제형변환 후 자동 형좁힘 ( 실수형 -> 정수형 ) 

printf("잘못된 나눗셈 = %d\n", sum);

avg = (double)(x/y); // 2.5가 아닌 2.0으로 나온 이유 x,y가 이미 정수형으로 연산된 후의 값에 강제형변환을 해서 정확한 값이 안나옴. 

printf("avg = %lf\n", avg);


avg = (double)x/y;

printf("정확한 나눗셈 = %lf\n", avg); 

 

return 0;




3. 복합대입연산자


  (1) 종류 : +=, -+, *=, /=, %/, >>=, <<=, &=, |=, ^=


  (2) 예제 (소스코드, 실행결과, 주석)


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

// 복합대입연산자 

int x,y;

x = y = 5;

printf("x = %d, y = %d\n", x, y);

printf("x += y의 결과는 %d\n", x+=y); // x = x + y

printf("x -= y의 결과는 %d\n", x-=y); // x = x - y

printf("x *= y의 결과는 %d\n", x*=y); // x = x * y

printf("x /= y의 결과는 %d\n", x/=y); // x = x / y

printf("x %%= y의 결과는 %d\n", x%=y); // x = x % y

return 0;

}




4. 관계연산자

  

  (1) 종류 : >, <, >=, <=, ==, !=


  (2) 예제 (소스코드, 실행결과, 주석)

#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

// 관계연산자 

int x,y;

printf("두정수 입력 : ");

scanf("%d%d", &x, &y);

printf("%d > %d 의 결과는 %d입니다.\n", x, y, x>y); // 결과가 참인 경우 리턴값이 1 

printf("%d == %d 의 결과는 %d입니다.\n", x, y, x==y); 

// 결과가 거짓인 경우 리턴값이0 


return 0;

}




5. 논리연산자

 

  (1) 종류 : &&, || !


  (2) 예제 (소스코드, 실행결과, 주석)

#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


int x,y,z;

x = 5; y = 10; z;

z = (x+=2) || (y+=1);

printf("x=%d,y=%d\n", x, y); 

printf("z=%d\n", z); // z = (x+=2) || (y+=1) 에서 x = 7이 되고 y = 11이 됨 0이 아닌 수는 참이므로 or 연산에서 참이 하나라도 있으면 결과값이 1 


return 0;

}




6. 조건연산자

  (1) 종류 : ?:

  (2) 예제 (소스코드, 실행결과, 주석)


 /*조건연산자 (조건식? 참: 거짓) 


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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


int n1,n2,max,min; 

 

printf("두정수 입력 : "); 


scanf("%d%d", &n1, &n2); 

 

(n1>n2) ? (max=n1 , min=n2) : (max=n2 , min=n1); 

 

printf("\n>> 큰 수 / 작은 수 = %d\n", max / min); 


printf(">> 큰 수 %% 작은 수 = %d\n", max % min); 


return 0;

}





7. 증감연산자

 

(1) 종류 : ++, --


(2) 예제 (소스코드, 실행결과, 주석)


//증감연산자 ++, --

// ++x (진위형, prefix) : x값 1증가후 연산수행

// --x 

// x++ (후위형, postfix) : x값 연산후 1증가 

// x-- 

//int x=5;

/*

int y=x++; // x는 y에 대입연산후 1증가 

printf("x=%d\n", x);

printf("y=%d\n", y);  

*/

/*

int y=++x; // x가 1증가후 y에 대입연산됨 

printf("x=%d\n", x);

printf("y=%d\n", y); 

*/

int a = 10, b = 20;

printf("a=%d\n", a++); // a에 10의 값이 대입연산후 1증가 

printf("a=%d\n", ++a); // 1의 값이 증가한후 a에 대입연산 

printf("a=%d\n", b--); // b에 20의 값이 대입연산후 1감소 

printf("a=%d\n", --b); // 1의 값이 감소한후 b에 대입연산 


return 0;

}




8. 비트연산자


(1) 종류 : &, |, ^, ~, <<, >>


(2) 예제 (소스코드, 실행결과, 주석)


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int x;

printf("정수입력 : ");

scanf("%d", &x);

printf("%d>>3=%d\n", x, x>>3); // 비트를 3번 이동한뒤 나누는 연산 (피연산자 나누기 2^3이 결과값으로 나옴) 

printf("%d<<3=%d\n", x, x<<3); // 비트를 3번 이동한뒤 곱하는 연산 (피연산자 곱하기 2^3이 결과값으로 나옴)

return 0;

}




9. 연산자의 우선순위


연산자 분류에 따른 우선순위 : 단항 > 산술 > 이동 > 관계 > 비트 > 논리 > 조건 > 대입 > 콤마 순이다.


연산자의 우선순위가 기억이 나지않는다면 괄호를 사용하여 강제로 우선순위를 지정할수있다.




'basic > C' 카테고리의 다른 글

6. 함수  (0) 2016.10.31
5. 배열  (0) 2016.10.13
4. 제어문(조건문과 반복문)  (0) 2016.10.06
2. C프로그래밍의 기초문법  (0) 2016.09.08
1. C프로그래밍의 기초  (0) 2016.09.05

1. 프로그램 작성 순서


(1) 변수 선언    프로그램에서 사용할 변수를 선언한다.


(2) 자료 입력    프로그램에 필요한 값을 입력한다.


(3) 자료 처리    알고리즘에 따라 C구문에 맞게 명령문을 작성한다.


(4) 자료 출력    실행 결과를 형식에 맞추어 출력장치에 표시한다.


(5) 합수 결과값 반환    main 함수의 결과값을 main 함수를 호출했던 곳으로 되돌려준다.




2. 변수 선언 형식


자료형     변수이름


3. 기본 자료형


 

 문자 자료형

크기

표현범위 

 문자

 char

1byte

-128~127 

 정수

 int

 4byte 


-2,147,483,648() ~ 2,147,483,647()

 

 실수

 double

 8byte

최솟값 :

최댓값 :



4. 출력 함수

1. printf ()


printf 괄호 속의 ,를 중심으로 전반부엔 변환명세를 후반부엔 출력할 값 및 수식을 넣을 수 


있다.


(a) 형식 printf("%d", 출력할 값,수식) / ex) printf("나이가 %d살 입니다.\n", 21); 의 결과물은

 변환명세                                              나이가 21살 입니다. 라고 나온다.


(b) 변환명세의 종류 


정수 : %d 자료형은 int이며 정수를 10진정수 형태로 출력


실수 : %lf 자료형은 double형이며 실수를 소수점 아래 6자리까지 출력


문자 : %c 자료형은 char형이며 문자 한개를 출력


문자열 : %s 자료형은 문자열이며 문자열을 출력한다.


%d, %lf, %c는 정수형, 실수형, 문자형 중 기본 자료형의 변환명세이다.


예제 프로그램(소스, 결과, 주석)


#include <stdio.h>

#include <stdlib.h>


int main() 

{

//1. 변수선언

int age=20;

double height=175.5;

char grade='A';

//2. 처리

//3. 출력 

printf("나이 %d 세 \n", age); //age의 값이 20이라는 정수이기 때문에 %d를 사용하였음. 


printf("키 %lf cm \n", height); //height의 값이 175.5라는 실수이기 때문에 %lf를 사용하였음. 

printf("표준체중 %lf kg \n", (height-100)*0.9); //수식의 결과값이 실수범위 이기 때문에 %lf를 사용하였음. 

printf("학점 %c \n)", grade); // grade의 결과값이 문자 하나라서 %c를 사용하였음 

printf("국적 : %s", "대한민국"); // 대한민국이라는 문자열 자료형을 출력하기위해 %s를 사용 

pirntf("10진수 = %d, 8진수= %o, 16진수= %x\n", age, age, age); /* 10진수의 변환명세는 %d, 8진수의 변환명세는 %o 

  16진수의 변환명세는 %x임 */ 

return 0;

}




(c) 변환명세의 필드폭 예제


(1) %d의 필드폭 예제소스 ,주석 ,실행결과


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int n=+123;

printf("1234567890\n");

printf("----------------------\n");

printf("%d\n", n);   //오른쪽에서 첫번째부터 출력한다 

printf("%5d\n", n);  //오른쪽에서 다섯번째부터 출력한다 

printf("%+5d\n", n); //+기호를 붙이면 정수값의 부호를 출력한다 

printf("%-5d\n", n); //필드폭 앞의 마이너스 부호는 왼쪽정렬 기능

printf("%-+5d\n", n);//왼쪽정렬후 정수값의 부호를 출력한다 

return 0;

}



(2) %f의 필드폭 예제소스, 주석, 실행결과


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

double avg = 83.768;

printf("12345678901234567890\n");

printf("%lf\n", avg); // 실수형은 기본 소수점 여섯자리 이하까지 출력 

printf("%7.3lf\n", avg); /* 전체 7자리중 소수점 3자리 이하까지 출력

(.의 전반부 소수자리 포함 전체 자리수 .의 후반부 소수 이하 n자리) */

printf("%6.2lf\n", avg); // 문제 : 전체 6자리중 소수 이하 2자리 출력 

printf("%.2lf\n", avg); // 소수 2자리 이하까지 출력 

printf("%10lf\n", avg); /* 전체 출력칸 10자리에서 소수점 아래 자리를 모두 출력 

나머지 왼쪽 칸에 소수점 위의 값과 소수점을 출력 */

printf("%5.lf\n", avg); /* 필드폭 5만큼 칸을 확보해 출력하되 소수점 아래 첫자리에서 

반올림하여 소수점 위의 값만 출력 */

return 0;

}




(3) %c의 필드폭 예제소스, 주석, 실행결과


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

char grade = 'a';

printf("I've got an %c.\n", grade); // 자료를 문자형으로 출력 

printf("I've got an %3c.\n", grade); // 3칸을 사용하며 문자를 오른쪽칸에 맞추어 출력 

printf("I've got an %-3c.\n", grade); // 문자를 맨 왼쪽 칸에 맞추어 3칸을 사용하여 출력 

return 0;

}




(4) %s 의 필드폭 예제소스, 주석, 실행결과


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

printf("%s!\n", "Hello"); // 문자열 출력 

 

printf("My name is %4s.\n", "Tom"); // 문자열을 오른쪽에서 부터 4번째 칸을 사용하여 출력 

printf("%-20s %-5s\n", "Nice to meet you.", "Bye!"); // 왼쪽 정렬하여 20칸을 사용하여 출력, 5칸을 사용하여 출력 

return 0;

}



(2) putchar()


(a) 특징 : 단일문자 출력, 개행 문자를 입력하지 않으면 옆으로 이어서 출력.


(b) 형식 : putchar(문자형 변수 또는 '문자');


(c) 예제

#include <stdio.h>

#include <stdlib.h>


int main(int argc, char *argv[]) 

{


char grade ='A';


//putchar() : 단일문자 출력

putchar(grade);

putchar('+');

putchar('\n'); //putchar 함수는 개행문자를 사용하지 않으면 옆으로 이어서 출력됨.

putchar('B');


return 0;


}




(3) puts ()


(a) 특징 : 문자열을 출력 개행을 자동으로 함.


(b) 형식 : puts(문자열 변수 or "문자열");


(c) 예제

#include <stdio.h>

#include <stdlib.h>


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


//puts() : 문자열 전용 출력함수

puts("hello"); // 문자열 출력 후 무조건 개행 문자가 출력됨. 

puts("My name is Hong GilDong"); //줄이 바뀜 


return 0;

}





5. 입력함수


(1) scanf()


(a) 형식 : scanf("변환명세", &변수);


(b) 특징 : scanf에서는 입력된 값을 저장할 메모리의 주소를 명시해야 하므로 변수명 앞에 &(주소연산자)를 반드시 붙인다


(c) 사용순서


순서 1. 입력받을 메시지를 출력 printf("국어점수,영어점수를 순서대로 입력하세요. ");


순서 2. 형식에 맞추어 사용

scanf("%d%d", &kor, &eng); //입력구분방법에서 공백이나 탭키를 사용하면 뛰워짐.

scanf("%d,%d", &kor, &eng); //입력구분방법을 ,로 하고싶으면 변환명세사이에 ,를 넣으면 됨 


순서 3. scanf()에서 사용한 변수선언 int kor, eng;


(d) 입력방법 3가지

1. 10 20        스페이스를 사용하여 구분입력 가능

2. 10    20     TAB키를 사용하여 구분입력 가능

3. 10            엔터키를 사용하여 구분입력 가능

20

특수기호(,)로 입력하는 경우 변환명세에 제시한다.


(e) 예제 1 - 1개 값 입력한 경우


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

//1. scanf() 함수 

//scanf("변환명세", &변수명)

/*scanf에서는 입력된 값을 저장할 메모리의 주소를 명시해야 하므로

변수명 앞에 &(주소연산자)를 반드시 붙인다.*/

int age; // 3. 입력값을 저장할 변수를 선언한다. 

printf("당신의 나이를 입력하세요 : "); //1. 입력내용 메시지 

//값을 하나만 입력받을 경우 

scanf("%d", &age);//2. 형식에 맞추어 사용. &변수명 


return 0;

}





(f) 예제 2 - 2개 이상 값을 입력한 경우


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

//순서 3. scanf()에서 사용한 변수선언 

int kor, eng;

//scanf()로 2개 이상의 값을 입력받는 경우

//순서 1. 입력받을 메시지를 출력 

printf("국어점수,영어점수를 순서대로 입력하세요. ");

//순서 2. 형식에 맞추어 사용

scanf("%d%d", &kor, &eng); //입력구분방법에서 공백이나 탭키를 사용하면 뛰워짐.

scanf("%d,%d", &kor, &eng); //입력구분방법을 ,로 하고싶으면 변환명세사이에 ,를 넣으면 됨 

printf("입력한 점수는 %d,%d입니다.\n", kor, eng); 

return 0;

}





(2) getchar()


(a) 특징 : 변환명세가 필요없이 단일문자를 입력한다.


(b) 형식 : 변수 = getchar();


(c) 예제


#include <stdio.h>

#include <stdlib.h>


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


char grade;

printf("학점입력 : ");

grade = getchar(); // 변환명세가 필요없이 단일문자를 입력 

printf("입력한 학점은 %c", grade);


return 0;

}




(3) gets() 

    

(a) 특징 : 문자열을 입력받는 함수, 문자열을 처리할때는 배열사용, 문자열을 입력할때 scanf를 사용하지 않는 이유는 문자열을 입력받을때 공백을 처리할수 없기때문에 gets를 사용

    

(b) 형식 : gets(문자열을 저장할 변수)

    

(c) 예제 


#include <stdio.h>

#include <stdlib.h>


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


char address[30]; //문자열을 처리할때는 배열사용

printf("주소 입력 : ");

/*scanf("%s", address);  문자열을 입력받을때 공백을 처리할수없기때문에 gets를 사용 */

gets(address); // 문자열을 입력받는 함수 

//배열의 이름만 적는이유 배열이름은 시작주소에서 null값이 있는곳까지 읽어오는 기능이 있기때문 

printf("입력한 주소는 %s\n", address);


return 0;

}




6. 숫자, 문자 입력시 문제점, 해결방법


숫자를 입력받고 그후 문자를 입력받기전 공백문자를 사용하게 되는데 이 공백문자를 문자로 인식하여 결과출력이 제대로 되지 않는 문제점이 생긴다.

그렇기에 이를 해결하기 위해 버퍼를 비워주는 함수 fflush(stdin)을 사용하여 버퍼를 비워준뒤 문자를 입력하면 올바르게 값이 나오는것을 확인할수있다.


#include <stdio.h>

#include <stdlib.h>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


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

int age;

char gender;

double height;

printf("나이 : ");

scanf("%d", &age);

printf("키 : ");

scanf("%lf", &height);

printf("성별(남자 M, 여자 F) : ");

/*원인 엔터키도 문자하나로 저장한다. 

문자 자료를 입력 받을 때는 공백문자(빈칸,탭키,엔터키)도 

입력 문자로 사용됨으로 문제가 발생할수있다. */

fflush(stdin); // 버퍼를 비워주는 함수 

gender = getchar();

//scanf("%c", &gender);

//해결방법 버퍼를 비워주는 함수를 사용한다. fflush(stdin) 

//결과출력 

printf("\n=======================\n");

printf(" 나이 : %d \n", age);

printf(" 키 : %.1lf \n", height);

printf(" 성별 : %c \n", gender);

return 0;

}






'basic > C' 카테고리의 다른 글

6. 함수  (0) 2016.10.31
5. 배열  (0) 2016.10.13
4. 제어문(조건문과 반복문)  (0) 2016.10.06
3. 연산자  (0) 2016.09.22
1. C프로그래밍의 기초  (0) 2016.09.05

1. 프로그램 개념


프로그램이란 수집한 데이터들을 통해 컴퓨터를 실행시키기 위해 차례대로 작성된 명령어들


예를 들어 공사 현장에서도 직접 일을 하는 인부들과 지시를 내리는 반장이 있듯이 이 반장이 들고있


는 작업 계획서가 프로그램의 개념으로 볼 수 있다.


2. 프로그램 개발과정


요구사항 분석 -> 알고리즘 설계 -> 프로그램 코딩 -> 컴파일링 -> 링킹 -> 실행 과정을 거치고 이 과정


의 전역에서 에러가 발생할 경우 논리 에러일 경우 알고리즘 설계 단계로, 그 밖의 에러들은 프로그램 코


딩단계로 돌아가서 다시 수정해야하는데 이러한 디버깅을 마쳐야 프로그램을 최종적으로 만들었다고 볼


수 있다. 


간단하게 설명하자면 위와 같겠고 이를 좀 더 정확히 자세히 알아보자면


우선적으로 요구 사항을 분석한다. 만들고자 하는 프로그램이 어떤 프로그램인지 프로그램을 사용자가


요구하는 사항이 무엇인지에 대해서 분석한다.


이후 프로그램의 알고리즘을 설계한다. - 알고리즘은 순서도나 의사코드를 이용하여 나타내는데 이를 이


용하면 알고리즘을 논리적이고 체계적으로 작성할 수 있다.


이런 알고리즘 설계 단계는 상당히 중효라고 프로그램의 효율성과 정확성을 결정하는 매우 중요한 


과정이라고 할 수 있다. 프로그램 개발과정중 코딩 단계가 중요할 것 같지만 실제로는 알고리즘 설계 과


정에 투자하는 시간이 더욱 많다고 볼 수 있다. 최악의 경우 프로그램이 거의 다 완성되어갔을 즈음 테스


트를 하다 알고리즘이 잘못되었다는것을 깨닫게 된다면 처음부터 모든 부분을 수정해야 할 수도 있다. - 


(알고리즘 설계 단계가 그 만큼 중요하다는 것을 알수있다.)


그 다음 프로그램 코딩과정을 거친다. 개발자들이 알고리즘을 프로그래밍 언어로 옮기는 작업을 코딩이


라고 하는데 이 작업을 마친 프로그램은 소스 코드 , 소스 파일 , 소스 프로그램이라고 한다.


위와 같이 코딩되어진 소스 파일들을 번역하는 과정이 컴파일링이라고 합니다. 이 작업을 수행하는 프로


그램을 컴파일러 라고 한다.


이제 분리된 여러개의 파일을 하나로 뭉치기 위한 링킹 과정을 거친다. 이 같은 작업은 링커가 수행하며 


프로그래머는 모든 코드를 직접 작성하지 않고 라이브러리를 이용할 수 도 있기때문에 이런 경우에도 


여러 소스 프로그램 파일을 하나로 합치고 관련된 코드를 실제 프로그램 안에 포함 시켜 하나로 만드는 


링킹 과정을 거쳐야 한다.


링킹 과정을 거치면 실행 파일이 만들어지는데 이 실행 파일은 로더에 의해 주기억장치에 저장되고 그 


후 CPU에 의해 실행된다.


프로그램이 완성되었다면 이 프로그램이 실행되는 것을 방해하는 버그를 찾아서 제거하는 작업을 해야


한다. 이러한 작업이 디버깅이라고 한다.


'basic > C' 카테고리의 다른 글

6. 함수  (0) 2016.10.31
5. 배열  (0) 2016.10.13
4. 제어문(조건문과 반복문)  (0) 2016.10.06
3. 연산자  (0) 2016.09.22
2. C프로그래밍의 기초문법  (0) 2016.09.08

+ Recent posts