본문 바로가기
728x90
반응형
SMALL

개념265

chapter 12) 문자열 상수가 주소란 증거 #include int main(void){ printf("save address value of 'apple' : %p\n", "apple"); printf("second letter of address ; %p\n", "apple" +1); printf("first letter : %c\n", *"apple"); printf("second letter ;%c\n", *("apple" + 1)); printf("third letter that type of arrays : %c\n", "apple"[2]); return 0; } main() 함수 1-1. "apple" 문자열의 주소 값을 %p 포맷 지정자를 사용하여 출력 1-2. "apple" 문자열의 주소에서 1을 더한 값(즉, 두 번째 문자의 주소.. 2024. 8. 23.
chapter 12) 두 문자열 중 길이가 긴 단어 출력 #include #include int main(void){ char str1[80], str2[80]; char *resp; printf("two fruit name : "); scanf("%s%s", str1, str2); if (strlen(str1) >strlen(str2)) resp = str1; else resp = str2; printf("long name of fruit is %s\n", resp); return 0; } main() 함수 1-1. 크기가 80인 char 배열 str1과 str2 선언, char 포인터 resp 선언 1-2. "two fruit name : " 출력 후 사용자로부터 두 개의 과일 이름을 str1과 str2에 입력 받음 1-3. `strlen(str1)`과 `.. 2024. 8. 22.
chapter 12) 개행 문자로 인해 gets 함수가 입력을 못하는 경우 #include int main(void){ int age; char name[20]; printf("input age : "); scanf("%d", &age); printf("input name : "); gets(name); printf("age :%d, name : %s\n", age, name); return 0; } main() 함수 1-1. 정수형 변수 age와 크기가 20인 char 배열 name 선언 1-2. "input age : " 출력 후 사용자로부터 나이를 입력 받아 age 변수에 저장 1-3. "input name : " 출력 후 `gets` 함수를 사용하여 사용자로부터 이름을 입력 받아 name 배열에 저장. `gets` 함수는 사용자가 입력한 문자열을 개행 문자가 나타나기 전.. 2024. 8. 21.
chapter 12) strcpy()와 기능이 같은 함수 구현 #include char *my_strcpy(char *pd, char *ps); int main(void){ char str[80] = "strawberry"; printf("before string :%s\n", str); my_strcpy(str, "apple"); printf("change letter : %s\n", str); printf("another insert string : %s\n", my_strcpy(str, "kiwi")); return 0; } char *my_strcpy(char *pd, char *ps){ char *po = pd; while(*ps != '\0'){ *pd = *ps; pd++; ps++; } *pd = '\0'; return po; } main() 함수 1.. 2024. 8. 20.
728x90
반응형
LIST