gcc로 컴파일 하는데 도저히 해결을 못해서 질문드립니다.

planck의 이미지

디지털 시계 프로그램을 만들어봤는데

clock1.c: In function ‘time_to_number’:
clock1.c:100: warning: assignment makes pointer from integer without a cast
clock1.c:101: error: dereferencing pointer to incomplete type
clock1.c:102: error: dereferencing pointer to incomplete type
clock1.c:103: error: dereferencing pointer to incomplete type

계속 이런 오류가 뜨는데 해당 오류가 무슨 소린지는 알겠는데 수정을 어떻게 해야할지 모르겠습니다.

이 함수가 계속 오류를 일으키고 있는 함수인데 어디를 어떻게 고쳐야할지 도무지 감이 잡히질 않네요.

long time_to_number()//시분초 단위의 값을 하나의 정수로 변환하는 함수
{
time_t current;
struct tm *d;
int hour, min, sec;
current = time(NULL);
d = localtime(&current);
hour = d->tm_hour * 10000;
min = d->tm_min * 100;
sec = d->tm_sec;r
return hour + min + sec;
}

꼭 답변해주시면 감사하겠습니다.

HDNua의 이미지

time_to_number 함수에서:

100: 경고: 캐스팅 없이 정수로 포인터를 할당했습니다.
> int *ptr = 1;과 같이 포인터에 정수 값이 바로 들어간 것 같습니다.

101: 오류: 불완전한 형식의 포인터를 디리퍼런싱 했습니다.
struct tm 구조체의 선언이 올바르게 되어있는지 확인하세요. 선언되지 않은 구조체라면 구조체에 접근할 수 없겠죠?

아마 tm에 관한 구조체가 제대로 포함되지 않았거나, struct tm;과 같이 전방 선언만 되어있고
struct tm { ... };의 선언이 없는 경우일 겁니다.

저는 이렇게 생각했습니다.

planck의 이미지

아직 문제 해결 중에 있지만
조언 감사드립니다.

HDNua의 이미지

저도 테스트해봤는데, Ubuntu 12.04 LTS에서 정상 동작합니다.

#include <stdio.h>
#include <time.h>
 
long time_to_number()//시분초 단위의 값을 하나의 정수로 변환하는 함수
{
        time_t current;
        struct tm *d;
        int hour, min, sec;
        current = time(NULL);
        d = localtime(&current);
        hour = d->tm_hour * 10000;
        min = d->tm_min * 100;
        sec = d->tm_sec;
        return hour + min + sec;
}
 
int main(void) {
        long time = time_to_number();
        long h = time / 10000; time %= 10000;
        long m = time / 100; time %= 100;
        long s = time;
 
        printf("%ld:%ld:%ld \n", h, m, s);
 
        return 0;
}

첫 번째 사진은 실행 결과입니다.

두 번째 사진은 코드에서 time.h 헤더를 주석 처리했을 때의 결과입니다.

댓글 첨부 파일: 
첨부파일 크기
Image icon , 2015-11-08 02:08:03.png213.88 KB
Image icon , 2015-11-08 02:11:34.png262 KB

저는 이렇게 생각했습니다.

planck의 이미지

해결되었네요!
정말 고맙습니다~

shint의 이미지


DevC++과 codepad.org 모두 컴파일은 잘 됩니다.

하지만. 인자값이 다른거 같습니다.
current = time(NULL);

함수 원형을 확인해주시기 바랍니다.
http://forum.falinux.com/zbxe/index.php?document_srl=408349&mid=C_LIB
http://linux.die.net/man/3/localtime
http://www.cplusplus.com/reference/ctime/localtime/
http://itguru.tistory.com/120
http://itguru.tistory.com/114
http://www.cplusplus.com/reference/ctime/time/

DevC++ 5.11

#include <iostream>
#include <stdio.h>
 
 
#include <stdio.h>
#include <time.h>
 
long time_to_number()//시분초 단위의 값을 하나의 정수로 변환하는 함수
{
    time_t current;
    struct tm *d;
    int hour, min, sec;
 
    current = time(NULL);
    d = localtime(&current);
    hour = d->tm_hour * 10000;
    min = d->tm_min * 100;
    sec = d->tm_sec;
    printf("%d %d %d\n", hour, min, sec);
    return hour + min + sec;
}
 
 
int main(int argc, char** argv) 
{
 
    time_to_number();
 
 
   char      *week[] = { "일", "월", "화", "수", "목", "금", "토"};
   time_t     current_time;
   struct tm *struct_time;
 
   time( &current_time);
 
   struct_time = localtime( &current_time);
 
   printf( "%4d 년\n",       struct_time->tm_year +1900);
   printf( "  %2d 월(0-11)\n", struct_time->tm_mon  +1   );
   printf( "  %2d 일(1-31)\n", struct_time->tm_mday      );
   printf( "%s요일\n"        , week[struct_time->tm_wday]);
   printf( "  %2d 시(0-23)\n", struct_time->tm_hour      );
   printf( "  %2d 분(0-59)\n", struct_time->tm_min       );
   printf( "  %2d 초(0-59)\n", struct_time->tm_sec       );
   printf( "1월 1일 이후의 날짜 수: %3d \n", struct_time->tm_yday);
 
   if      ( 0 <  struct_time->tm_isdst)  printf( "썸머 타임 사용\n"     );
   else if ( 0 == struct_time->tm_isdst)  printf( "썸머 타임 사용 안함\n");
   else                                   printf( "썸머 타임 사용 불가\n");
 
 
    return 0;
}
 
 
 
#if 0
20000 4000 24
2015 년
  11 월(0-11)
   8 일(1-31)
일요일
   2 시(0-23)
  40 분(0-59)
  24 초(0-59)
1월 1일 이후의 날짜 수: 311
썸머 타임 사용 안함
#endif

http://codepad.org

160000 2200 14
2015 년
  11 월(0-11)
   7 일(1-31)
토요일
  16 시(0-23)
  22 분(0-59)
  14 초(0-59)
1월 1일 이후의 날짜 수: 310 
썸머 타임 사용 안함

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

planck의 이미지

제가 지금 애를 먹고있는게 윈도우 환경에서 만들어진 저 프로그램을 리눅스 환경으로 고치고 있는 작업 중에 생긴 문제였습니다.
리눅스를 제가 처음하다보니 저 함수를 도데체 어떻게 변형해야 할지 모르겠네요
일단 답변 주신 것 대단히 감사합니다.

댓글 달기

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