strtok_s 사용이 미숙합니다..
잠팅이
질문 제목 : strtok_s 사용이 미숙하네요..txt파일을 가져와 strtok_s 로 내용을 자르고 싶어요.질문 내용 :
txt파일로 저장된 것을 불러와 strtok_s으로 문자열을 분리하고 싶은데 생각처럼 잘 되지 않네요 ..
txt파일에서 불러오는 것 대신...
char buf[128] = {a|s|d|f|g|h}; 로 해 보면.. 분리는 되나, 쓰레기값이 딸려서 출력된다고 하나요?
어찌 수정을 해 보아야 할까요 ?
stdmethodimp ctestctrl::onload(void)
{
// todo: 여기에 구현 코드를 추가합니다.
handle hfile;
dword dwread;
char buf[128];
lpcwstr filename = _t(c:\\testctrl.txt);
hfile = createfilew(filename,generic_read,0,null,open_existing,file_attribute_normal,null);
readfile(hfile,buf,strlen(buf),&dwread,null);
closehandle(hfile);
// char buf[128] = {a|s|d|f|g|h};
char* pseparator = |;
char* ptoken = null;
char* pcontext;
ptoken = strtok_s(buf, pseparator, &pcontext);
while (ptoken != null)
{
::messagebox
(
getactivewindow(),
(lpcwstr)ptoken, (lpcwstr)ptoken,
mb_yesno | mb_iconinformation
);
ptoken = strtok_s(null, pseparator, &pcontext);
}return s_ok;
}