반응형

2016/11/29 7

[C언어 소스]유니코드와 ASCII 코드 문자열 길이

[C언어 소스]유니코드와 ASCII 코드 문자열 길이 #include #include #include int main() { char c ='a'; wchar_t wc = L'홍'; char name[10]="홍길동"; wchar_t wname[10]=L"홍길동"; setlocale(LC_ALL,"Korean"); //로케일 설정(지역 설정) printf("c:%c wc:%lc\n",c,wc); printf("name:%s wname:%ls\n",name,wname); printf("name 길이:%d wname 길이:%d\n",strlen(name), wcslen(wname)); return 0; } 실행 결과c:a wc:홍 name:홍길동 wname:홍길동 name 길이:6 wname 길이:3 본문[..

[C언어 소스] char 형식 배열에 문자열 초기화

[C언어 소스] char 형식 배열에 문자열 초기화 #include #define MAX_NAME_LEN 50 #define MAX_ADDR_LEN 100 int main() { char name[MAX_NAME_LEN+1] = {'a','b','c'}; char addr[MAX_ADDR_LEN+1] = "제주도 제주시 애월읍 고내리"; printf("이름:%s\n",name); printf("주소:%s\n",addr); return 0; } 실행 결과이름:abc 주소:제주도 제주시 애월읍 고내리 본문[디딤돌 C언어] 69. 문자열 사용 기초

[C언어 소스] 문자열에 관한 함수

[C언어 소스] 문자열에 관한 함수 //디딤돌 C언어 http://ehpub.co.kr//문자열에 관한 함수#pragma warning(disable:4996)#include #include int main(){ char name[10] = ""; strcpy(name, "hello"); printf("이름:%s\n", name); printf("문자열 길이:%d\n", strlen(name)); if (strcmp(name, "hello") == 0) { printf("차이가 없다.\n"); } else { printf("차이가 있다.\n"); } return 0;} 실행 결과이름:hello 문자열 길이:5 차이가 없다. 본문[디딤돌 C언어] 68. 문자열

[C언어 소스] 배열과 포인터를 이용한 문자열 사용

[C언어 소스] 배열과 포인터를 이용한 문자열 사용 #include int main() { char name1[6]="hello"; char name2[6]="hello"; const char *str1 = "yahoo"; const char *str2 = "yahoo"; printf("name1: %p name2:%p\n",name1,name2); printf("str1: %p str2:%p\n",str1,str2); name1[0] = 'y'; //str1[0] = 'k'; //값을 변경할 수 없음 printf("name1: %s name2: %s\n",name1,name2); printf("str1: %s str2: %s\n",str1,str2); return 0; } 실행 결과name1: 0023..

[C언어 소스] 선택 정렬 (Selection Sort, 내림 차순)

[C언어 소스] 선택 정렬 (Selection Sort, 내림 차순) Program.c//디딤돌 C언어 http://ehpub.co.kr//선택 정렬 (내림차순) //의사 코드(pseudo code)//함수 SelectionSort : 정수들이 있는 시작 위치 n : 원소 개수)//반복: n이 0보다 클 동안// base에서 n 개의 원소 중에 제일 큰 위치를 찾아 max_pos에 대입// max_pos와 base 위치의 원소를 교환// n을 1 감소, base를 다음 위치로 이동(for문의 후처리 구문) #include #include void Swap(int *a, int *b);//두 수를 바꾸는 함수int *GetMaxPos(int *base, int n);//최대값 위치 찾는 함수void Sel..

[C언어 소스] n 개의 정수 중에 최대값 위치 구하는 함수

[C언어 소스] n 개의 정수 중에 최대값 위치 구하는 함수//디딤돌 C언어 http://ehpub.co.kr//n 개의 정수 중에 최대값 위치 구하는 함수 //의사 코드(pseudo code)//함수 GetMaxPosbase : 정수들이 있는 시작 위치 n : 원소 개수)//max_index를 0으로 초기화//index를 1로 초기화(for문의 초기 구문)//반복: index가 n보다 작을동안// 조건 : base[index]가 base[max_index]보다 크다면// index를 1 증가(for문의 후처리 구문)// base에서 max_index를 더한 위치를 반환 #include #include int *GetMaxPos(int *base, int n);int main(){ int arr[10] ..

[C언어 소스] n 개의 정수의 합계를 구하는 함수

[C언어 소스] n 개의 정수의 합계를 구하는 함수 //디딤돌 C언어 http://ehpub.co.kr//n 개의 정수의 합계를 구하는 함수 //의사 코드(pseudo code)//함수 GetSum(base: 더할 정수들이 있는 시작 위치 n : 원소 개수)//sum을 0으로 초기화//lcnt를 0으로 초기화(for문의 초기 구문)//반복: lcnt가 n보다 작을동안// 현재 sum에 base에서 상대적 거리 lcnt의 원소를 더함// lcnt를 1 증가(for문의 후처리 구문)// sum 반환 #include #include int GetSum(int *base, int n);int main(){ int arr[5] = { 1,2,3,4,5 }; assert(GetSum(arr,5) == 15); as..

반응형