Skip to content

Instantly share code, notes, and snippets.

@SangRyul
Created May 26, 2018 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SangRyul/5c3b327a9f9329b489e6e85a7a629fc0 to your computer and use it in GitHub Desktop.
Save SangRyul/5c3b327a9f9329b489e6e85a7a629fc0 to your computer and use it in GitHub Desktop.
/*program 1 함수 포인터*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//void simple_adder(int n1, int n2);
//void show_string(char *str);
//
//int main(void) {
//
// char *str = "함수 포인터 예시";
// int num1 = 10, num2 = 20;
//
// void(*fptr1)(int, int) = simple_adder;
// void(*fptr2)(char *) = show_string;
//
// fptr1(num1, num2);
// fptr2(str);
//
// system("pause");
// return 0;
//}
//
//void simple_adder(int n1, int n2) {
// printf("%d + %d = %d\n", n1, n2, n1 + n2);
//}
//
//void show_string(char *str) {
// printf("%s\n", str);
//}
/*program 2 함수 포인터2*/
// 아래의 소스코드 처럼 전달되는 인자에 따라서 달리 동작하는 함수의 정의도 가능하다.
//#include<stdio.h>
//
//int who_is_first(int age1, int age2, int(*cmp)(int n1, int n2));
//int older_first(int age1, int age2);
//int younger_first(int age1, int age2);
//
//int main(void) {
//
// int age1 = 20;
// int age2 = 30;
// int first;
//
// printf("입장순서1 \n");
// first = who_is_first(age1, age2, older_first);
// printf("%d세와 %d세 중 %d세가 먼저 입장 \n\n", age1, age2, first);
//
// printf("입장순서2 \n");
// first = who_is_first(age1, age2, younger_first);
// printf("%d세와 %d세 중 %d세가 먼저 입장 \n\n", age1, age2, first);
//
//
// system("pause");
// return 0;
//
//}
//
//int who_is_first(int age1, int age2, int(*cmp)(int n1, int n2)) {
// return cmp(age1, age2);
//}
//
//int older_first(int age1, int age2) {
// if (age1 > age2) {
// return age1;
// }
// else if (age1 < age2) {
// return age2;
// }
// else {
// return 0;
// }
//}
//
//int younger_first(int age1, int age2) {
// if (age1 < age2) {
// return age1;
// }
// else if (age1 > age2) {
// return age2;
// }
// else {
// return 0;
// }
//}
/*program 3 void형 포인터*/
//
//#include<stdio.h>
//int main(void) {
//
// char c = 3;
// double d = 3.1;
//
// void * vx = NULL;
//
// vx = &c; // char형 변수 c의 주소를 저장
// printf("vx의 주소값 : %x \n", vx);
// //printf("vx의 값 : %d \n", *vx); // 에러
// /*printf("*vx의 값 : %d \n", *(char*)vx);*/
//
// vx = &d;
// printf("vx의 주소값 : %x \n", vx);
// //printf("vx의 값 : %lf \n", *vx); // 에러
// /*printf("*vx의 값 : %lf \n", *(double*)vx);*/
//
// system("pause");
//
// return 0;
//
//}
/*program4*/
//#pragma warning(disable:4996)
//#include<string.h>
//#include<stdio.h>
//
//int main(void) {
//
// char buf1[20] = "Hello";
// char buf2[20] = "Hello";
//
// strcat(buf1, "World!");
// strncat(buf2, "World!", 5);
//
// printf("%s \n%s \n", buf1, buf2);
//
// system("pause");
// return 0;
//
//}
/*program 5*/
//#pragma warning(disable:4996)
//#include<string.h>
//#include<stdio.h>
//
//int main(void) {
//
// char buf[20];
// int line = 1;
//
// while (1) {
//
// printf("Input string ==> ");
// scanf("%s", buf);
//
// if (!strcmp(buf, "quit"))
// break;
// printf("%2d:%s\n", line++, buf);
//
// }
//
//
// system("pause");
//
// return 0;
//}
/*program 6*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(void) {
//
// char buffer1[20];
// char buffer2[20];
//
// strcpy(buffer1, "Array");
// printf("%s \n", buffer1);
//
// strcpy(buffer2, "Copy");
// printf("%s \n", buffer2);
//
//
// strcpy((buffer1 + 5), "Copy");
// printf("%s \n", buffer1);
//
// system("pause");
//
// return 0;
//
//
//
//
//}
/*program 7*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(void) {
//
// char buff[20] = "hello world!";
//
// printf("%d \n", strlen(buff));
//
// system("pause");
//
// return 0;
//
//
//}
/*program 8*/
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(void) {
//
// char *str = "ABCDEFG";
// char *ptr = NULL;
//
// ptr = strchr(str, 'E');
// printf("%c \n", *ptr);
//
// system("pause");
// return 0;
//
//
//}
/*program 9*/
//#pragma warning(disable:4996)
//#include <stdio.h>
//#include <string.h>
//
//int main(void)
//{
// char str[] = "forum falinux com";
// char *ptr;
// int ndx;
//
// ptr = strtok(str, " ");
// printf("%s\n", ptr);
//
// while (ptr = strtok(NULL, " "))
// {
// printf("%s\n", ptr);
// }
//
// system("pause");
// return 0;
//}
//program10
//#pragma warning(disable:4996)
//#include<stdio.h>
//#include<stdlib.h>
//int main(void) {
//
// int n;
// printf("몇개의 int형 정수를 할당하시겠습니까? \n");
// scanf("%d", &n);
//
// int* p = (int*)malloc(n * sizeof(int));
//
// for (int i = 0; i < n; i++) {
// p[i] = i;
// }
//
// for (int i = 0; i < n; i++) {
// printf("%d ", p[i]);
// }
//
// free(p);
// p = NULL;
//
// system("pause");
// return 0;
//
//}
//program 11
//#pragma warning(disable:4996)
//#include<stdio.h>
//#include<stdlib.h>
//int main(void) {
//
// int n;
// printf("몇개의 int형 정수를 할당하시겠습니까? \n");
// scanf("%d", &n);
//
// int* p = (int*)calloc (n , sizeof(int));
//
// for (int i = 0; i < n; i++) {
// printf("%d ", p[i]);
// }
// printf("\n-------------------------------\n");
//
// for (int i = 0; i < n; i++) {
// p[i] = i;
// }
//
// for (int i = 0; i < n; i++) {
// printf("%d ", p[i]);
// }
//
// free(p);
// p = NULL;
//
// system("pause");
// return 0;
//
//}
//program 12
//#pragma warning(disable:4996)
//#include<stdio.h>
//#include<stdlib.h>
//
//int main(void) {
//
//
//
// int *p = (int*)malloc(sizeof(int) * 2);
// p[0] = 10;
// p[1] = 20;
//
// p = (int*)realloc(p, sizeof(int) * 4);
// p[2] = 30;
// p[3] = 40;
//
// for (int i = 0; i < 4; i++) {
// printf("p[%d] : %d\n", i, p[i]);
// }
//
// free(p);
// p = NULL;
//
//
//
// system("pause");
// return 0;
//}
//program13
//#pragma warning(disable:4996)
//#include<stdio.h>
//
//int main(int argc, char* argv[]) {
//
//
// printf("문자열의 수 : %d\n", argc);
//
// for (int i = 0; i < argc; i++) {
// printf("argv[%d] : %s \n", i, argv[i]);
// }
//
// system("pause");
//
// return 0;
//
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment