반응형

분류 전체보기 658

(C언어) strrchr: 문자열에서 지정된 마지막 문자를 찾는다

#include char *strrchr(const char *s, int c); strrchr 함수는 문자열 s에서 지정된 문자 c와 일치하는 마지막 문자를 찾습니다. 문자를 찾았으면 찾은 문자의 포인터를 반환하고, 찾지 못했으면 NULL을 반환합니다. 참고: strchr, strpbrk #include #include int main() { char s[]= "Scans a string for the last occurrence of a character."; char* ptr; ptr = strrchr(s, 'c'); if(ptr) printf("%d 위치에서 문자를 찾았습니다\n",ptr-s); else printf("문자를 찾지못했습니다\n"); return 0; }

(C언어) strpbrk: 문자열 검색

#include char *strpbrk(const char *s1, const char *s2); strpbrk 함수는 문자열에서 주어진 문자열을 찾기 위해 문자열을 스캐닝합니다. 문자열을 찾았으면 첫 번째로 찾은 문자열의 포인터를 반환하고, 찾지 못했으면 NULL을 반환합니다. 참고: strrchr #include #include int main() { char s[]= "Scans strings for characters in specified character sets."; char* ptr; ptr = strpbrk(s, "char"); if(ptr) printf("문자열을 찾았습니다\n"); else printf("문자열을 찾지못했습니다\n"); return 0; }

(C언어) strnset: 문자열을 주어진 문자로 초기화한다

#include char *strnset(char *s, int ch, size_t n); strnset 함수는 문자열을 n 크기만큼 주어진 문자로 초기화합니다. Initializes characters of a string to a given character. 비주얼스튜디어에서는 strnset 함수 대신에 _strnset 함수를 사용해야 합니다. #define _CRT_SECURE_NO_WARNINGS #include #include int main() { char s[]= "Initializes characters of a string to a given character."; _strnset(s, 'x', strlen(s)); printf("%s\n", s); return 0; }

(C언어) strncpy: 지정된 크기만큼 문자열을 복사한다

#include char *strncpy(char *dest, const char *str, size_t maxlen); strncpy 함수는 지정된 크기만큼의 문자열을 다른 문자열에 복사합니다. NULL 문자를 자동으로 덧붙이지 않기 때문에 필요하면 NULL 문자를 추가해야 합니다. #define _CRT_SECURE_NO_WARNINGS #include #include int main() { char s[100]; char s2[] = "string copy"; strncpy(s, s2, 6); s[6] = '\0'; printf("%s\n", s); return 0; }

(MySQL) DISTINCT: 중복된 행 제거하기

SQL의 DISTINCT 구분을 이용하면 결과로 출력되는 행의 중복된 값을 제거할 수 있습니다. 다음은 학생(student) 테이블의 내용입니다. mysql> select * from student; 학과코드(deptCD)를 조회해 보겠습니다. mysql> select deptCD from student; 기본으로 모든 학생의 학과코드가 출력되기 때문에 중복된 값이 출력되었습니다. 중복된 값을 1개씩만 출력되도록 distinct 키워드를 사용해 보겠습니다. mysql> select DISTINCT deptCD from student; COUNT 함수를 이용해서 중복된 값을 제거한 학과코드의 갯수도 구할 수 있습니다. mysql> select COUNT(DISTINCT deptCD) from student;

Database/MySQL 2023.03.05

(C언어) strncmp, _strnicmp: 문자열의 일부를 (대소문자 구분없이) 비교한다

#include int strncmp(const char *s1, const char *s2, size_t maxlen); int strnicmp(const char *s1, const char *s2, size_t maxlen); int _strnicmp(const char *s1, const char *s2, size_t maxlen); strncmp 함수는 문자열 s1과 s2를 지정한 maxlen 길이만큼만 비교합니다. strnicmp 함수는 문자열 s1과 s2를 지정한 maxlen 길이만큼 대소문자 구분없이 비교합니다. s1

(C언어) strncat: 문자열을 일부를 다른 문자열에 추가한다

#include char *strncat(char *dest, const char *src, size_t maxlen); strncat 함수는 문자열 src의 일부를 문자열 dest에 추가합니다. src에서 maxlen 개의 문자를 dest에 추가하고 NULL도 추가합니다. 참고: strcat #define _CRT_SECURE_NO_WARNINGS // Visual Studio #include #include int main() { char s[100] = "C,C++,"; char s2[] = "C#,Java,Python"; strncat(s, s2, 7); printf("%s\n", s); return 0; }

반응형