noname02
문자열 관련 함수 본문
문자 출력 함수
#include <stdio.h>
int putchar(int c);
int fputc(int c, FILE* stream);
공통
- 오류 발생 시 EOF 리턴.
문자 입력 함수
#include <stdio.h>
int getchar(void);
int fgetc(FILE* stream);
공통
- 에러, 파일 끝 도달시 EOF 리턴.
문자열 출력 함수
#include <stdio.h>
int puts(const char* s);
- 자동으로 줄을 바꿔줌.
int fputs(const char* s, FILE* stream);
- 자동으로 줄을 바꿔주지 않음.
공통
- 오류 발생 시 EOF 리턴.
문자열 입력 함수
#include <stdio.h>
char* gets(char* s);
- 리턴값 받는 변수의 크기가 입력받은 값보다 크면 overflow가 되므로 사용하지 않음.
char* fgets(char* s, int n, FILE* stream);
- n에 크기를 넣는다. 보통 sizeof연산자 사용.
공통
- 에러, 파일 끝 도달시 NULL 포인터 리턴.
- \n 까지 입력을 받음.
- 길이 n을 초과하면 n-1개의 문자까지 입력받고 마지막에 NULL 문자 삽입.
문자열 길이 반환 함수
#include <string.h>
size_t(unsigned int) strlen(const char* s)
- 문자열 길이 리턴.
- NULL문자 이전까지 리턴.
- \n 등 포함.
문자열 복사 함수
#include <string.h>
char* strcpy(char* dest, const char* src);
- sizeof(const char* src)<sizeof(char* dest)인 경우 overflow 발생.
char* strncpy(char* dest, const char* src, size_t n);
- size_t n의 길이 만큼 복사함.
- 만일sizeof(const char* src)<sizeof(char* dest)인 경우, n-1길이까지 복사하고, 마지막에 NULL문자를 삽입하게 소스를 짬.
공통
- 리턴 시 복사된 문자열 포인터 리턴.
- char* dest -> const char* src 로 복사함.
문자열 추가 함수
#include <string.h>
char* strcat(char* dest, const char* src);
- char* dest의 크기가 dest+src 길이보다 크면 overflow 발생.
char* strncat(char* dest, const char* src, size_t n);
- n의 크기 만큼 문자열을 복사한다.
공통
- const char* src 문자열을 char* dest 문자열 뒤에 붙인다. 이 때, char* dest 문자열 뒤에있던 NULL문자는 삭제된다.
- 추가된 문자열의 포인터를 리턴함. 즉, char* dest 인자의 배열 주소값을 리턴한다.
문자열 비교 함수
#include <string.h>
int strcmp(const char* s1, const char* s2);
int strncmp(const char* s1, const char* s2, size_t n);
-문자열을 처음부터 n개까지만 비교
공통
//아스키 값을 기준으로
- s1>s2인 경우 +값 리턴
- s1==s2인 경우 0 리턴
- s1<s2인 경우 -값 리턴
문자열 숫자 반환 함수
#include <stdlib.h>
int, long, double atoi(char *ptr);
- 문자열을 int, long, double 형으로 변환
대소문자 변환 함수
#include <ctypes.h>
int toupper(int c);
- 소문자를 대문자로 변환
int tolower(int c);
- 대문자를 소문자로 변환
'Study > C' 카테고리의 다른 글
const 키워드 (0) | 2015.04.04 |
---|---|
static 변수 (0) | 2015.04.04 |
서식 문자, 특수 문자 (0) | 2015.04.02 |
main함수의 인자 (0) | 2015.04.02 |
파일 관련 함수 (0) | 2015.04.02 |