[질문] strptime 함수에 관해서..

leolo의 이미지

#include <time.h>
#include <stdio.h>
#include <time.h>
int main()
{
        struct tm tms;
        char *buffer = "03/22/99";
        strptime(buffer, "%x", &tms);
        printf("days of year: %d\n", tms.tm_yday);
        return 0;
}

위 코드를 -Wall 옵션으로 컴파일 하면.
아래와 같이 warning이 뜹니다. 물론, 앞에다 함수의 형을 선언하면 나타나지 않습니다. 형 선언 이외에 다른 방법은 없나요.
레드헷 9.0입니다.

[ering@localhost test]$ gcc -o c c.c -Wall
c.c: In function `main':
c.c:8: warning: implicit declaration of function `strptime'

한가지 더 질문이 있습니다.
예를 들어 120초가 있는데요. 이 것을 00:00:00 포멧으로
변경하고 싶은데 어떻게 하면 되죠..
제가 해봤는데요..
아래와 같이 하면 시간 단위에서 -9를 해야 정상적으로 되더군요.
이유를 잘 모르겠습니다.

#include <stdio.h>
#include <time.h>

int main()
{
    char tel_time[128];
    int tel;
    struct tm rp, *tp;
    time_t time;
    char *time_format = "%X";
    tel = 123;
    time = (time_t)tel;
    tp = localtime_r(&time, &rp);
    memset(tel_time, 0x00, (sizeof(char)*128));
    sprintf(tel_time, "%02d:%02d:%02d", rp.tm_hour, rp.tm_min, rp.tm_sec);
    printf("tel[%s] \n", tel_time);
    memset(tel_time, 0x00, (sizeof(char)*128));
    sprintf(tel_time, "%02d:%02d:%02d", rp.tm_hour - 9, rp.tm_min, rp.tm_sec);
    printf("tel[%s] \n", tel_time);
    return 0;
}
[/code]
버려진의 이미지

소스에 #include <time.h> 가 두번씩이나 ^^

그 경고는 #define _XOPEN_SOURCE 으로 해결됩니다.

glibc2와 관련된 건데 자세한건 구글링..;; (점심 먹으러 가야 합니다 =3)

leolo의 이미지

컴파일 시.. -D_XOPEN_SOURCE 옵션을 주면..
간단하게 만든 테스트 프로그램에서는 됩니다.
그런데, 소스에 적용시키면 다른 에러가 잔뜩 나타나서..
쩝..

실력이 있으면 삶이 편하다... 영차 영차...

pbb의 이미지

#include 전에 #define __USE_XOPEN과 #define _GNU_SOURCE을 선언해 주면 waring이 없어 집니다.
관련 링크는 아래와 같습니다.
https://stackoverflow.com/questions/15334558/compiler-gets-warnings-when-using-strptime-function-c

pbb의 이미지

오타가 나서 정정 합니다. #define __USE_XOPEN과 #define _GNU_SOURCE 은 #include 전에 선언 해 줍니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.