1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #include<stdio.h> #include<stdlib.h> #include<string.h> #pragma warning(disable: 4996) // 자신의 집주소를 입력 받아서 // 집주소 길이 만큼 heap을 할당받고 //넣고 출력해보기 int main() { /* int a[5]; int* p; p = a; *p = 10; int* k; k = (int *)malloc(sizeof(int)*5); *k = 10; */ /* char address[100]; //scanf("%[^\n]", address); gets_s(address); int len = strlen(address); char* p; p = (char *)malloc(sizeof(char) * len+1); //마지막 NULL 문자 공간 // p = address; strcpy(p, address); printf("%s", p); free(p); return 0; */ /* char** p; p = (char **)malloc(sizeof(char*) * 1); *p = (char *)malloc(sizeof(char) * 3); **p = 'A'; //printf("%d %d %d", p, *p, **p); printf("%c",**p); free(*p); free(p); */ /* char str[100]; char** p; int num, i = 0; printf("원하는 문장의 개수를 입력하세요:"); scanf("%d", &num); p = (char **)malloc(sizeof(char*)*num); for (i = 0; i < num; i++) { printf("%d 번째 문장은?", i + 1); scanf("%s", str); *p = (char *)malloc(sizeof(char)*strlen(str)); strcpy(*p, str); printf("%s\n", *p); **p++; } for (i = 0; i < num; i++) { printf("%s\n", *p + i); } for (i = 0; i < num; i++) { free(*p + i); } free(p); */ char **p; int cnt,i; char buf[100]; printf("원하는 문장의 개수?"); scanf("%d", &cnt); getchar(); p = (char**)malloc(sizeof(char*) * cnt); for (i = 0; i < cnt; i++) { printf("%d번째 문장은?", i + 1); gets_s(buf); *(p+i) = (char *)malloc(sizeof(char)*strlen(buf) + 1); strcpy(*(p+i), buf); } for (i = 0; i < cnt; i++) { puts(*(p+i)); } for (i = 0; i < cnt; i++) { free(*(p + i)); } free(p); } | cs |
'딥러닝 기반 영상인식 개발 전문가 과정 > C언어, Python, 자료구조' 카테고리의 다른 글
5월15일 Queue (0) | 2019.05.16 |
---|---|
5월 15일 더블 링크드 문제 (0) | 2019.05.15 |
5월14일 파일읽어와서 구조체에쓰기/ 상품명,가격,단가 등등으로 정렬하기 (0) | 2019.05.15 |
5월 13일 싱글링크드리스트 (0) | 2019.05.14 |
5월 13일 파일입출력, 파일복사 소스코드 (0) | 2019.05.14 |