🧼C, C++/자체제작 프로그램및 배포
C++ memstrs 헤더파일
Mawile
2020. 9. 13. 07:29
일단 앞서 설명전에 사용한언어는
STDC++11에서 정상작동 확인되었습니다
안녕하세요
어.. 이번에는 저가 memset과 memchr C++라이브러리함수를 이용해서 간단하게 헤더파일을 만들어봤어요
이런거같은경우는
memset(str+0,'p',1)
memchr(str,'h',strlen(str))
등등 메모리안의 값을 바꾸거나 메모리안의 내용을 보려면 하나하나씩 값을 넣어야 하지만
저가 만든 memstrs헤더를 통해 문자열을 입력하며 바로 메모리에 다 입력이되도록했습니다
헤더파일은 하단에 github링크로 첨부해 놓았습니다~
함수는 총 2개있는데요
memsets();
memchrs();
이며,
함수원형은 이렇습니다
int memsets(char[],string)
long long int memchrs(char[],string)
사용법은 간단합니다
메모리내용을 정하거나 메모리내에서 찾을 값을 정하면됩니다
저가 만든 예제코드입니다.
#include "memstrs.h"
int main(){
long long int pch;
char str1[] = "star";
char str2[] = "posion";
memsets(str1,"hello");
cout << str1 << endl; //memsets정상작동확인을 위한 결과출력
pch = memchrs(str1,"hello");
cout << pch; //memchrs함수는 찾은단어의 제일첫번째 인덱스번호를 반환
//찾지못할경우 -1을 반환합니다
}
만약에 memset함수를 통해 특정구간부터 바꾸고싶다면?
memsets(str1+2,"hello");
이러면은 인덱스번호2번 즉,
배열에서의 3번째부터바뀌겠죠??
이상으로 저의 글을 봐주셔서 감사합니다!
DRAGONPROCESS/memstrs-headerfile
Contribute to DRAGONPROCESS/memstrs-headerfile development by creating an account on GitHub.
github.com