c에서 typedef sturct 큐에 삽입하는 것에대한 문제 ..

Sailor_moon의 이미지

안녕하세요 ...구조체에 뭔가 에러가 나네요 ... 봐주시면 감사하게ㅆ습니다...

#define STATUS_WAITING 100
#define TO_H_CITY 200
...
typedef struct cars_list {         //차들을 구조체로 선언합니다. 방향과 상태를 가집니다 ..
    int status;
    int direction;
    struct cars_list* next;
} CARS;
 
이렇게 선언을 하여ㅆ구요 ..
 
CARS *queue = NULL;             // 전역변수들 ...
CARS *queue_H = NULL;            
void enqueue(CARS* member);
CARS* dequeue(CARS* queue);
void enqueue_H(CARS* member);
CARS* dequeue_H(CARS* queue);

각각의 방향별로 두가지 큐(queue , queue_H) 를 만들어서 , 랜덤하게 생성하여 해당하는 방향의 큐에 각각 담으려고 합니다.메인함수에서 그래서 ..아래와 같은 함수를 호출하였는데 ..
난수를 발생시켜서 일단 넣어보려고하니 , 에러가 발생합니다.
에러 메시지는 다음과 같습니다 ....

gcc -g -o hw2 hw2.c hw2.h -lpthread
hw2.c: In function ‘generate_Cars’:
hw2.c:35:4: error: incompatible type for argument 1 of ‘enqueue_H’
hw2.h:45:6: note: expected ‘struct CARS *’ but argument is of type ‘CARS’
 
 
 
 
main ()
{
...
generate_Cars();
...
}
void generate_Cars()
{
    int j;
    int val;
    for (j=0 ; j<MAX; j++){
        val = rand()%2; //generate radon values 0 or 1
        printf("%d\n", val);
 
        if (val==0){    //GENERATE HANOVER direction car
            CARS c= {STATUS_WAITING, TO_H_CITY, NULL};    // H 방향 자동차 ...
            enqueue_H(c);            // 요기서 문제발생 !!!
        }
 
        else {     
            printf("hello \n");
        }
    }
}

...

아래는 큐 삽입함수입니다...

void enqueue(CARS* member)        // put member cars to each queues ..
{
    CARS* t_list;
    CARS* s_list;
    if ( queue == NULL )
    {
        queue = (CARS*)malloc(sizeof(CARS));
        queue->status = member->status;
        queue->direction = member->direction;
        queue->next = queue;
    }
    else
    {
    // If there already exists one or more nodes...
        t_list = (CARS*)malloc(sizeof(CARS));
        queue->status = member->status;
        queue->direction = member->direction;
        t_list->next = queue->next;    // Find a last queue node... and add to there ...
        queue->next = t_list;
        queue = t_list;            // 새로운 노드의 다음을 queue의 처음을 가르키게 한다.
    }
 
} 

번외 질문입니다만 ;쓰레드를 차량갯수 만큼 만들기 위해 .. 아래처럼 배열로 하려고 하니 ... 에러가 나더군요 ;;;어떻게 생성하는것이 좋죠 ?

pthread_t[MAX];

초보인지라 자주 질문만 해서 너무 죄송해요 .....
그래도 이곳에서 하나하나 배워가는 재미에 계속 공부하는 중입니다 ... 도움 부탁드려요 ...

댓글 달기

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