[완료] 문자열에 구분기호 삽입하기.

munamuna의 이미지

안녕하세요.. __);

날자&시간을 다음과 같은 형식으로 받습니다.

20090101131110

이걸 보기 쉽게 다음과 같이 변경하려고 합니다.

2009/01/01 13:11:10

루프를 돌려서 처리를 하자니 무언가 뽀대(?)가 안나는듯 싶고요...;;

CString이라면 SetAt()함수를 쓰면 간단히 되긴 하지만 char 배열이니.. 무언가 함수를 만들어서 써야 할것 같은데요.

좋은 아이디어나 방법 알고 계시면 부탁드리겠습니다.

혹시 문자열에 문자 삽입하는 함수가 제공되던가요?

klyx의 이미지

C에서도 당연히 되지만, CString을 쓴다는건 C++일테니, std::string을 써보세요.

munamuna의 이미지

질문이 좀 모호한지라 수정을 했는데.. 그사이에 답변을 달아주셨네요..__);
CString을 사용하지 못하는 상황입니다..

bushi의 이미지

strptime(), strftime()

OTL

munamuna의 이미지

시스템 시간을 얻어오는게 아니라..

저 문자열 형식을 서버로부터 받아와서 그걸 구분기호를 넣어서 로그에 출력하는 것입니다.. __);

당근.. 서버한테 "구분기호 넣어서 넘겨주세요"라고 해봐야 무시당합니다...ㅠㅠ;

bushi의 이미지

국어 이해력, 남들 못지않다고 자부하고 있습니다.
에혀.

man strptime

char *strptime(const char *s,  const  char  *format,  struct  tm *tm);
...
       The  strptime() function is the converse function to strftime(3)
       and converts the character string pointed  to  by  s  to  values
       which are stored in the tm structure pointed to by tm, using the
       format specified by format.

man strftime

size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
...
       The  strftime() function formats the broken-down time tm accord-
       ing to the format specification format and places the result  in
       the character array s of size max.

strptime() 을 사용해서 20090101131110 을 struct tm 에 담고,
strftime() 을 사용해서 struct tm 에 있는 것을 2009/01/01 13:11:10 으로 바꾸세요.

OTL

munamuna의 이미지

죄송합니다.. strftime만 보고 답변을 달았네요..;;

답변 감사드립니다.. ^^

whitelazy의 이미지

로그파일에 출력할꺼면 걍 하나씩 출력하면서 카운트해서 위치나오면 끼워넣고 출력하고 다음꺼 출력하고 하는식이 제일 빠르지 않나요?
어차피 저장이야 바이트단위인걸...
물론 메모리에서 처리하고 저장하는게 더 빠르겠지만 어차피 내부야 버퍼일뿐...

bushi의 이미지

이분은 뽀대를 원하십니다.

OTL

netionics의 이미지

int year, month, day;
int hour, min, sec;

scanf("%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &min, &sec);
printf("%.4d/%.2d/%.2d %.2d:%.2d:%.2d", year, month, day, hour, min, sec);

:)

cppig1995의 이미지

.4, .2가 아니라 04, 02일 것 같습니다.

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

munamuna의 이미지

두분 모두 답변 감사드립니다... ^^

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.