printf("ho_tari\n");
C언어(5) 본문
2025.02.24
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
/*
int main(void) {
char str[80];
char result[80] = { 0 };
int i = 0;
printf("단어 입력 : ");
scanf("%s", str);
for (; i < strlen(str); i++)
{
if (i < 5)
{
result[i] = str[i];
}
else
{
result[i] = '*';
}
}
// result[i] = '\0'; // 처음에 result[80]을 0으로 초기화 안해줬을 때 작성
printf("입력한 단어 : %s, 생략한 단어 : %s", str, result);
return 0;
}
*/
/*
int main(void) {
char str1[80], str2[80], str3[80];
char temp[80];
printf("세 단어 입력 : ");
scanf("%s%s%s", str1, str2, str3);
if (strcmp(str1, str2) > 0)
{
strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, temp);
}
if (strcmp(str1, str3) > 0)
{
strcpy(temp, str1);
strcpy(str1, str3);
strcpy(str3, temp);
}
if (strcmp(str2, str3) > 0)
{
strcpy(temp, str2);
strcpy(str2, str3);
strcpy(str3, temp);
}
printf("%s, %s, %s", str1, str2, str3);
return 0;
}*/
/*
void strswap(char* pa, char* pb);
int main(void) {
char word1[20];
char word2[20];
char word3[20];
printf("세 단어 입력 : ");
scanf("%s%s%s", word1, word2, word3);
if (strcmp(word1, word2) > 0) strswap(word1, word2);
if (strcmp(word2, word3) > 0) strswap(word2, word3);
if (strcmp(word1, word3) > 0) strswap(word1, word3);
printf("%s, %s, %s", word1, word2, word3);
return 0;
}
void strswap(char* pa, char* pb) {
char temp[80];
strcpy(temp, pa);
strcpy(pa, pb);
strcpy(pb, temp);
}*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
/*
void assign() {
int a;
a = 10;
printf("assign 함수 a : %d\n", a);
}
int main(void) {
auto int a = 0; // auto 생략 가능
assign();
printf("main 함수의 a : %d\n", a);
return 0;
}
*/
//int main(void) {
// int a = 10;
//
// printf("블럭 전 : %d\n", a);
// {
// int a = 20;
// printf("블럭 내 : %d\n", a);
// }
// printf("블럭 후 : %d\n", a);
//
// return 0;
//}
/*
void assign10(void);
void assign20(void);
int a;
int main(void) {
printf("함수 호출 전 a 값 : %d\n", a);
assign10();
assign20();
printf("함수 호출 후 a 값 : %d\n", a);
return 0;
}
void assign10(void) {
a = 10;
}
void assign20(void) {
int a;
a = 20;
}*/
/*
void auto_func(void);
void static_func(void);
int main(void) {
int i;
printf("일반 지역 변수(auto)를 사용한 함수...\n");
for (i = 0; i < 3; i++)
{
auto_func();
}
printf("정적 지역 변수(static)를 사용한 함수...\n");
for (i = 0; i < 3; i++)
{
static_func();
}
return 0;
}
void auto_func(void) {
auto int a = 0;
a++;
printf("%d\n", a);
}
void static_func(void) {
static int a = 0;
a++;
printf("%d\n", a);
}*/
/*
int main(void) {
register int i;
auto int sum = 0;
for (i = 1; i <= 10000; i++)
{
sum += i;
}
printf("%d\n", sum);
return 0;
}*/
/*
void add_ten(int a);
int main(void) {
int a = 10;
add_ten(a);
printf("a : %d\n", a);
return a;
}
void add_ten(int a) {
a = a + 10;
}*/
/*
void add_ten(int *pa);
int main(void) {
int a = 10;
int* pt;
pt = &a;
add_ten(pt);
printf("a : %d\n", a);
return a;
}
void add_ten(int *pa) {
*pa = *pa + 10;
}*/
int main(void) {
app();
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
/*
int* sum(int a, int b);
void app() {
int* resp;
resp = sum(10, 20);
printf("두 정수의 합 : %d\n", *resp);
}
int* sum(int a, int b) {
static int res; // 어떤 값을 주소로 반환할 경우 반드기 정적 변수로 선언되어야 한다.
res = a + b;
return &res;
}
*/
/*
void input_data(int* pa, int* pb);
void swap_data(void);
void print_data(int a, int b);
int a, b;
void app() {
input_data(&a, &b);
swap_data();
print_data(a, b);
return 0;
}
void input_data(int* pa, int* pb) {
printf("두 정수 입력 : ");
scanf("%d %d", pa, pb);
}
void swap_data(void) {
int temp;
temp = a;
a = b;
b = temp;
}
void print_data(int a, int b) {
printf("두 정수 출력 : %d, %d", a, b);
}*/
/*
void app() {
int score[3][4];
int total;
double avg;
int i, j;
for (i = 0; i < 3; i++)
{
printf("4과목의 점수 입력 : ");
for (j = 0; j < 4; j++)
{
scanf("%d", &score[i][j]);
}
}
for (i = 0; i < 3; i++)
{
total = 0;
for (j = 0; j < 4; j++)
{
total += score[i][j];
}
avg = total / 4.0;
printf("총점 : % d, 평균 : % .2lf\n", total, avg);
}
return 0;
}*/
/*
void app() {
// int score[3][4];
int score[12];
int total;
double avg;
int i, j;
for (i = 0; i < 3; i++)
{
printf("4과목의 점수 입력 : ");
for (j = 0; j < 4; j++)
{
scanf("%d", &score[i * 4 + j]);
}
}
for (i = 0; i < 3; i++)
{
total = 0;
for (j = 0; j < 4; j++)
{
total += score[i * 4 + j];
}
avg = total / 4.0;
printf("총점 : % d, 평균 : % .2lf\n", total, avg);
}
return 0;
}
*/
/*
void app() {
int score1[3][4];
int score2[12];
int total;
double avg;
int i, j;
for (i = 0; i < 3; i++)
{
printf("4과목의 점수 입력 : ");
for (j = 0; j < 4; j++)
{
scanf("%d", &score1[i][j]);
}
}
memcpy(score2, score1, 12 * sizeof(int));
for (i = 0; i < 3; i++)
{
total = 0;
for (j = 0; j < 4; j++)
{
total += score2[i * 4 + j];
}
avg = total / 4.0;
printf("총점 : % d, 평균 : % .2lf\n", total, avg);
}
return 0;
}*/
/*
void app() {
int num[3][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};
int i, j;
for (i = 0; i < 3; i++)
{
for(j = 0; j < 4; j++)
{
printf("%5d", num[i][j]);
}
printf("\n");
}
return 0;
}*/
/*
void app() {
char animal[5][20];
int i;
int count;
count = sizeof(animal) / sizeof(animal[0]);
for (i = 0; i < count; i++)
{
scanf("%s", animal[i]);
}
for (i = 0; i < count; i++)
{
printf("%s ", animal[i]);
}
return 0;
}*/
/*
void app() {
char animal1[5][10] = {
{'d', 'o', 'g', '\0'},
{'t', 'i', 'g', 'e', 'r', '\0'},
{'r', 'a', 'b', 'b', 'i', 't', '\0'},
{'h', 'o', 'r', 's', 'e', '\0'},
{'c', 'a', 't', '\0'}
};
char animal2[][10] = { "dog", "tiger", "rabbit", "horse", "cat" };
int i;
for (i = 0 ; i < 5; i++)
{
printf("%s ", animal1[i]);
}
printf("\n");
for (i = 0; i < 5; i++)
{
printf("%s ", animal2[i]);
}
return 0;
}*/
/*
void app() {
int score[2][3][4] = {
{{72, 80, 95, 60}, {68, 98, 83, 90}, {75, 72, 84, 90}},
{{66, 85, 90, 88}, {95, 92, 88, 95}, {43, 72, 56, 75}}
};
int i, j, k;
for (i = 0; i < 2; i++)
{
printf("%d반 점수...\n", i + 1);
for (j = 0; j < 3; j++)
{
for (k = 0; k < 4; k++)
{
printf("%5d", score[i][j][k]);
}
printf("\n");
}
printf("\n");
}
return 0;
}*/
/*
void app() {
char* pary[5];
int i;
pary[0] = "dog";
pary[1] = "elephant";
pary[2] = "horse";
pary[3] = "tiger";
pary[4] = "lion";
for (i = 0; i < 5; i++)
{
printf("%s\n", pary[i]);
}
return 0;
}*/
/*
void app() {
char* pary[5] = { "dog", "elephant", "horse", "tiger", "lion" };
int i;
for (i = 0; i < 5; i++)
{
printf("%s\n", pary[i]);
}
}*/
/*
void app() {
int ary1[4] = { 1, 2, 3, 4 };
int ary2[4] = { 11, 12, 13, 14 };
int ary3[4] = { 21, 22, 23, 24 };
int* pary[3] = { ary1, ary2, ary3 };
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
{
printf("%5d", pary[i][j]);
}
printf("\n");
}
}*/
/*
void app() {
int ary1[4] = { 1, 2, 3, 4 };
int ary2[4] = { 11, 12, 13, 14 };
int ary3[5] = { 21, 22, 23, 24, 25 };
int* pary[3] = { ary1, ary2, ary3 };
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 5; j++)
{
printf("%5d", pary[i][j]);
}
printf("\n");
}
}*/
/*
void app() {
char a[4][10] = { "horse", "fox", "hippo", "tiger" };
char* pa[] = { a[0], a[1], a[2], a[3] };
int count;
int i;
count = sizeof(pa) / sizeof(pa[0]);
for (i = 0; i < count; i++)
{
printf("%c", pa[i][i]);
}
return 0;
}*/
/*
void app() {
int ary[5][6] = {
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15},
{16, 17, 18, 19, 20}
};
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 5; j++)
{
ary[4][j] += ary[i][j];
ary[i][5] += ary[i][j];
ary[4][5] += ary[i][j];
}
}
for (i = 0; i < 5; i++)
{
for (j = 0; j < 6; j++)
{
printf("%5d", ary[i][j]);
}
printf("\n");
}
return 0;
}*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void app_multi_dimension() {
int num[5][6] = { 1, 2, 3, 4, 5, 0, 6, 7, 8, 9, 10, 0, 11, 12, 13, 14, 15, 0, 16, 17, 18, 19, 20, 0 };
int x, y, sum = 0;
for (y = 0; y < 4; y++)
{
for (x = 0; x < 5; x++)
{
num[4][x] += num[y][x];
num[y][5] += num[y][x];
printf("%5d", num[y][x]);
}
printf("%5d\n", num[y][5]);
}
for (x = 0; x < 5; x++)
{
sum += num[4][x];
printf("%5d", num[4][x]);
}
printf("%5d", sum);
}
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
/*
void app() {
int a = 10;
int* pa = &a;
printf("변수 a의 주소는 %p입니다.", &a);
}*/
/*
void app() {
int a = 10;
int* pa;
int** ppa;
pa = &a;
ppa = &pa;
printf("------------------------------------------------------\n");
printf("변수 변숫값 &연산 *연산 **연산 \n");
printf("------------------------------------------------------\n");
printf(" a%12d%12u\n", a, &a);
printf(" pa%12u%12u%12d\n", pa, &pa, *pa);
printf("ppa%12u%12u%12u%12u\n", ppa, &ppa, *ppa, **ppa);
printf("------------------------------------------------------\n");
}*/
/*
void swap_ptr(char** ppa, char** ppb);
void app() {
char* pa = "success";
char* pb = "failure";
printf("pa -> %s, pb -> %s\n", pa, pb);
swap_ptr(&pa, &pb);
printf("pa -> %s, pb -> %s\n", pa, pb);
}
void swap_ptr(char** ppa, char** ppb) {
char* pt;
pt = *ppa;
*ppa = *ppb;
*ppb = pt;
}*/
/*
void print_str(char** pps, int cnt);
void app() {
char* ptr_ary[] = { "eagle", "tiger", "lion", "squirrel" };
int count;
count = sizeof(ptr_ary) / sizeof(ptr_ary[0]);
print_str(ptr_ary, count);
return 0;
}
void print_str(char** pps, int cnt) {
int i;
for (i = 0; i < cnt; i++)
{
printf("%s\n", pps[i]);
}
}*/
/*
void app() {
int ary[5];
printf("ary의 값 : %u\t", ary);
printf("ary의 주소 : %u\n", &ary);
printf("ary + 1 : %u\t", ary + 1);
printf("&ary + 1 : %u\n", &ary + 1);
return 0;
}*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int sum(int, int);
/*
int* fp(int, int); // 포인터 리턴을 가진 함수를 선언
int (*fp)(int, int); // 함수 포인터를 선언
*/
void app() {
int (*fp)(int, int);
int res;
// fp = sum;
res = (*sum)(10, 20);
printf("result : %d\n", res);
}
int sum(int a, int b) {
return a + b;
}
0224(1).c
0.00MB
0224(2).c
0.00MB
double_pointer.c
0.00MB
func_pointer.c
0.00MB
multi_dimension.c
0.00MB
variable.c
0.01MB