티스토리 뷰

문자 분류 데이터 변환 관련 라이브러리
# 라이브러리 함수 이해
1. 종류
1) 헤더 파일 : string.h
2) 복사함수
strlen : 문자열의 길이를 반환
int count=0;
while(str[i]!=NULL) {
count++;
i++;
}
int count=0;
while(str[i]!=NULL) {
count++;
i++;
}
2) 복사함수
memcpy : 메모리 블록을 복사
memmove : 메모리 블록을 이동
strcpy : 문자열을 복사
strncpy : 문자열 개수를 지정하여 복사
3) 연결함수memmove : 메모리 블록을 이동
strcpy : 문자열을 복사
strncpy : 문자열 개수를 지정하여 복사
strcat : 문자열을 연결
strncat : 문자열 개수를 지정하여 연결
strncat : 문자열 개수를 지정하여 연결
# 라이브러리 함수 활용
1. 길이함수

2. 복사함수



3. 연결함수


#include
#include
intmain ()
{
char szInput[256];
printf("Enter a sentence: ");
gets (szInput);
printf("The sentence entered is %u characters long.\n",(unsigned)strlen(szInput));
return 0;
}
// 결과값
Enter sentence: just testing
The sentence entered is 12 characters long.

#include
#include
intmain( void)
{
char *ptr_sour= “Good Morning!";
char *ptr_dest;
ptr_dest= (char *)malloc( 20);
memcpy( ptr_dest, ptr_sour, strlen( ptr_sour)+1); // NULL까지포함하기위해+1
printf( "%s\n", ptr_dest);
free( ptr_dest);
return 0;
}
// 결과값
Good Morning!

#include
#include
int main ()
{
char str[] = "memmove can be very useful......";
memmove (str+20,str+15,11);
puts (str);
return 0;
}
//결과값
memmove can be very very useful.

#include
#include
int main ()
{
char str1[]="Sample string";
char str2[40];
char str3[40];
strcpy (str2,str1);
strcpy (str3,"copy successful");
printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
return 0;
}
// 결과값
str1 : Sample string
str2 : Sample string
str3 : copy successful

#include
#include
int main ()
{
char str[80];
strcpy (str,"these ");
strcat (str,"strings ");
strcat (str,"are ");
strcat (str,"concatenated.");
puts (str);
return 0;
}
// 결과값
these strings are concatenated.
'JAVA기반스마트웹개발2021 > 프로그래밍언어 활용' 카테고리의 다른 글
도서관리 시스템 고도화(라이브러리 적용) (0) | 2021.08.08 |
---|---|
문자열 비교 검색 라이브러리 (0) | 2021.08.08 |
수학 관련 라이브러리 (0) | 2021.08.07 |
도서관리 시스템 (0) | 2021.08.07 |
문자처리 라이브러리 (0) | 2021.08.07 |